Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ScipDotnet.Tests/SnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private static string[] ListSnapshotInputDirectories()
#endif
}

private static string IndexDirectory(string directory)
internal static string IndexDirectory(string directory)
{
var include = Environment.GetEnvironmentVariable("SCIP_INCLUDE");
var framework = $"net{Environment.Version.Major}.0";
Expand Down Expand Up @@ -182,7 +182,7 @@ private static string[] GitLsFiles(string directory)
return process.StandardOutput.ReadToEnd().Trim().Split("\n");
}

private static string RootDirectory()
internal static string RootDirectory()
{
var process = new Process()
{
Expand Down
53 changes: 53 additions & 0 deletions ScipDotnet.Tests/SymbolKindTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Scip;
using Index = Scip.Index;
using Kind = Scip.SymbolInformation.Types.Kind;

namespace ScipDotnet.Tests;

[TestFixture]
public class SymbolKindTests
{
private static readonly Dictionary<string, Kind> ExpectedKinds = new()
{
["SymbolKinds/IShape#"] = Kind.Interface,
["SymbolKinds/Point#"] = Kind.Struct,
["SymbolKinds/Color#"] = Kind.Enum,
["SymbolKinds/Color#Red."] = Kind.EnumMember,
["SymbolKinds/Handler#"] = Kind.Delegate,
["SymbolKinds/Kinds#"] = Kind.Class,
["SymbolKinds/Kinds#Constant."] = Kind.Constant,
["SymbolKinds/Kinds#Field."] = Kind.Field,
["SymbolKinds/Kinds#StaticField."] = Kind.StaticField,
["SymbolKinds/Kinds#`.ctor`()."] = Kind.Constructor,
["SymbolKinds/Kinds#Property."] = Kind.Property,
["SymbolKinds/Kinds#StaticProperty."] = Kind.StaticProperty,
["SymbolKinds/Kinds#Event#"] = Kind.Event,
["SymbolKinds/Kinds#StaticEvent#"] = Kind.StaticEvent,
["SymbolKinds/Kinds#Method()."] = Kind.Method,
["SymbolKinds/Kinds#StaticMethod()."] = Kind.StaticMethod,
["SymbolKinds/KindsExtensions#"] = Kind.Class,
["SymbolKinds/KindsExtensions#Extension()."] = Kind.StaticMethod,
["SymbolKinds/VBClass#"] = Kind.Class,
["SymbolKinds/VBModule#"] = Kind.Module,
};

[Test]
public void DefinitionsCarrySymbolKindAndDocumentsDeclareUtf16()
{
var directory = Path.Join(SnapshotTests.RootDirectory(), "snapshots", "input", "symbol-kinds");
var index = Index.Parser.ParseFrom(File.ReadAllBytes(SnapshotTests.IndexDirectory(directory)));

var kinds = index.Documents.SelectMany(document => document.Symbols).ToList();
foreach (var (suffix, expected) in ExpectedKinds)
{
var matches = kinds.Where(info => info.Symbol.EndsWith(" " + suffix)).Select(info => info.Kind).ToList();
Assert.That(matches, Has.Count.EqualTo(1), suffix);
Assert.That(matches[0], Is.EqualTo(expected), suffix);
}

Assert.That(index.Documents.Select(document => document.Language).Distinct(),
Is.EquivalentTo(new[] { "C#", "Visual Basic" }));
Assert.That(index.Documents.Select(document => document.PositionEncoding),
Has.All.EqualTo(PositionEncoding.Utf16CodeUnitOffsetFromLineStart));
}
}
2,798 changes: 2,413 additions & 385 deletions ScipDotnet/Scip.cs

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion ScipDotnet/ScipDocumentIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Scip;
using Document = Scip.Document;
using Kind = Scip.SymbolInformation.Types.Kind;

namespace ScipDotnet;

Expand Down Expand Up @@ -175,6 +176,29 @@ private SymbolDescriptor.Types.Suffix SymbolSuffix(ISymbol sym)
}
}

// SymbolInformation.Kind from the Roslyn symbol; anything not listed stays UnspecifiedKind.
private static Kind ScipKind(ISymbol sym) => sym switch
{
INamedTypeSymbol { TypeKind: TypeKind.Class } => Kind.Class,
INamedTypeSymbol { TypeKind: TypeKind.Interface } => Kind.Interface,
INamedTypeSymbol { TypeKind: TypeKind.Struct } => Kind.Struct,
INamedTypeSymbol { TypeKind: TypeKind.Enum } => Kind.Enum,
INamedTypeSymbol { TypeKind: TypeKind.Delegate } => Kind.Delegate,
INamedTypeSymbol { TypeKind: TypeKind.Module } => Kind.Module,
IMethodSymbol { MethodKind: MethodKind.Constructor or MethodKind.StaticConstructor } => Kind.Constructor,
IMethodSymbol { MethodKind: MethodKind.Ordinary, IsStatic: true } => Kind.StaticMethod,
IMethodSymbol { MethodKind: MethodKind.Ordinary } => Kind.Method,
IPropertySymbol { IsIndexer: false, IsStatic: true } => Kind.StaticProperty,
IPropertySymbol { IsIndexer: false } => Kind.Property,
IFieldSymbol { ContainingType.TypeKind: TypeKind.Enum } => Kind.EnumMember,
IFieldSymbol { IsConst: true } => Kind.Constant,
IFieldSymbol { IsStatic: true } => Kind.StaticField,
IFieldSymbol => Kind.Field,
IEventSymbol { IsStatic: true } => Kind.StaticEvent,
IEventSymbol => Kind.Event,
_ => Kind.UnspecifiedKind,
};

private static string MethodDisambiguator(ISymbol sym)
{
if (sym is not IMethodSymbol)
Expand Down Expand Up @@ -241,7 +265,7 @@ public void VisitOccurrence(ISymbol? symbol, Location location, bool isDefinitio
if (!isDefinition) return;

// Emit SymbolInformation for this definition occurrence.
var info = new SymbolInformation { Symbol = scipSymbol };
var info = new SymbolInformation { Symbol = scipSymbol, Kind = ScipKind(symbol) };
_doc.Symbols.Add(info);

var symbolSignature = symbol.ToDisplayString(_format);
Expand Down
2 changes: 1 addition & 1 deletion ScipDotnet/ScipDotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<None Include="../LICENSE" Pack="true" PackagePath="" />
<None Include="../readme.md" Pack="true" PackagePath="" />
<PackageReference Include="Google.Protobuf" Version="3.30.0" />
<PackageReference Include="Google.Protobuf" Version="3.34.2" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.7.8" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="5.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="5.3.0" />
Expand Down
1 change: 1 addition & 0 deletions ScipDotnet/ScipProjectIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ await host.Services.GetRequiredService<MSBuildWorkspace>()
Scip.Document doc = new()
{
Language = language,
PositionEncoding = Scip.PositionEncoding.Utf16CodeUnitOffsetFromLineStart,
RelativePath = document.FilePath == null
? null
: Path.GetRelativePath(options.WorkingDirectory.FullName, document.FilePath)
Expand Down
Loading