Skip to content

Commit 0b7d9ca

Browse files
authored
Add Visual Basic support (#26)
Previously, scip-dotnet only supported C#. This PR adds support for Visual Basic as well. We are able to reuse a lot of code from the C# indexer by extracting shared logic related to formatting symbols.
1 parent 2a3aa88 commit 0b7d9ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5418
-464
lines changed

ScipDotnet.Tests/SnapshotTests.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ private Dictionary<String, SymbolInformation> SymbolTable(Document document)
214214

215215
private string FormatDocument(Index index, Document document)
216216
{
217+
var commentChar = document.Language == "C#" ? "//" : "'";
217218
var sb = new StringBuilder();
218219
var inputPath = new Uri(index.Metadata.ProjectRoot + "/" + document.RelativePath).LocalPath;
219220
var occurrences = document.Occurrences.ToList();
@@ -237,7 +238,11 @@ private string FormatDocument(Index index, Document document)
237238
var role = isDefinition ? "definition" : "reference";
238239
var length = range.End.Character - range.Start.Character;
239240
var indent = new String(' ', range.Start.Character);
240-
sb.Append("//")
241+
if (document.Language == "Visual Basic")
242+
{
243+
indent += " ";
244+
}
245+
sb.Append(commentChar)
241246
.Append(indent)
242247
.Append(new String('^', length))
243248
.Append(' ')
@@ -248,7 +253,7 @@ private string FormatDocument(Index index, Document document)
248253
if (isDefinition)
249254
{
250255
var info = symtab.GetValueOrDefault(occurrence.Symbol, new SymbolInformation());
251-
var prefix = "//" + indent + new String(' ', length + 1);
256+
var prefix = commentChar + indent + new String(' ', length + 1);
252257
foreach (var documentation in info.Documentation)
253258
{
254259
sb.Append(prefix).Append("documentation ").AppendLine(documentation.Replace("\n", "\\n"));
@@ -272,8 +277,6 @@ private string FormatDocument(Index index, Document document)
272277
return sb.ToString();
273278
}
274279

275-
private static int CompareOccurrences(Occurrence a, Occurrence b)
276-
{
277-
return Range.FromOccurrence(a).CompareTo(Range.FromOccurrence(b));
278-
}
280+
private static int CompareOccurrences(Occurrence a, Occurrence b) =>
281+
Range.FromOccurrence(a).CompareTo(Range.FromOccurrence(b));
279282
}

ScipDotnet/IndexCommandHandler.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public static async Task<int> Process(IHost host, List<FileInfo> projects, strin
3939
return 0;
4040
}
4141

42-
private static FileInfo OutputFile(FileInfo workingDirectory, string output)
43-
{
44-
return Path.IsPathRooted(output) ? new FileInfo(output) : new FileInfo(Path.Join(workingDirectory.FullName, output));
45-
}
42+
private static FileInfo OutputFile(FileInfo workingDirectory, string output) =>
43+
Path.IsPathRooted(output) ? new FileInfo(output) : new FileInfo(Path.Join(workingDirectory.FullName, output));
4644

4745
private static async Task ScipIndex(IHost host, IndexCommandOptions options)
4846
{
4947
var stopwatch = Stopwatch.StartNew();
50-
var indexer = host.Services.GetRequiredService<ScipIndexer>();
48+
var indexer = host.Services.GetRequiredService<ScipProjectIndexer>();
5149
var index = new Scip.Index
5250
{
5351
Metadata = new Metadata
@@ -71,18 +69,16 @@ private static async Task ScipIndex(IHost host, IndexCommandOptions options)
7169
stopwatch.Elapsed.ToFriendlyString());
7270
}
7371

74-
private static string FixThisProblem(string examplePath)
75-
{
76-
return
77-
"To fix this problem, pass the path of a solution (.sln) or project (.csproj) file to the `scip-dotnet index` command. " +
78-
$"For example, run: scip-dotnet index {examplePath}";
79-
}
72+
private static string FixThisProblem(string examplePath) =>
73+
"To fix this problem, pass the path of a solution (.sln) or project (.csproj/.vbrpoj) file to the `scip-dotnet index` command. " +
74+
$"For example, run: scip-dotnet index {examplePath}";
8075

8176
private static List<FileInfo> FindSolutionOrProjectFile(FileInfo workingDirectory, ILogger logger)
8277
{
8378
var paths = Directory.GetFiles(workingDirectory.FullName).Where(file =>
8479
string.Equals(Path.GetExtension(file), ".sln", StringComparison.OrdinalIgnoreCase) ||
85-
string.Equals(Path.GetExtension(file), ".csproj", StringComparison.OrdinalIgnoreCase)
80+
string.Equals(Path.GetExtension(file), ".csproj", StringComparison.OrdinalIgnoreCase) ||
81+
string.Equals(Path.GetExtension(file), ".vbproj", StringComparison.OrdinalIgnoreCase)
8682
).ToList();
8783

8884
if (paths.Count != 0)
@@ -91,7 +87,7 @@ private static List<FileInfo> FindSolutionOrProjectFile(FileInfo workingDirector
9187
}
9288

9389
logger.LogError(
94-
"No solution (.sln) or .csproj file detected in the working directory '{WorkingDirectory}'. {FixThis}",
90+
"No solution (.sln) or .csproj/.vbproj file detected in the working directory '{WorkingDirectory}'. {FixThis}",
9591
workingDirectory.FullName, FixThisProblem("SOLUTION_FILE"));
9692
return new List<FileInfo>();
9793
}

ScipDotnet/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static async Task<int> Main(string[] args)
1919
{
2020
var indexCommand = new Command("index", "Index a solution file")
2121
{
22-
new Argument<FileInfo>("projects", "Path to the .sln (solution) or .csproj file")
22+
new Argument<FileInfo>("projects", "Path to the .sln (solution) or .csproj/.vbproj file")
2323
{ Arity = ArgumentArity.ZeroOrMore },
2424
new Option<string>("--output", () => "index.scip",
2525
"Path to the output SCIP index file"),
@@ -43,7 +43,7 @@ public static async Task<int> Main(string[] args)
4343
indexCommand.Handler = CommandHandler.Create(IndexCommandHandler.Process);
4444
var rootCommand =
4545
new RootCommand(
46-
"SCIP indexer for the C# programming language. Built with the Roslyn .NET compiler. Supports MSBuild.")
46+
"SCIP indexer for the C# and Visual basic programming languages. Built with the Roslyn .NET compiler. Supports MSBuild.")
4747
{
4848
indexCommand,
4949
};
@@ -60,7 +60,7 @@ public static async Task<int> Main(string[] args)
6060
host.ConfigureServices((_, collection) =>
6161
collection
6262
.AddSingleton(_ => CreateWorkspace())
63-
.AddTransient<ScipIndexer>()
63+
.AddTransient<ScipProjectIndexer>()
6464
.AddTransient(services => (Workspace)services.GetRequiredService<MSBuildWorkspace>())
6565
);
6666
})

0 commit comments

Comments
 (0)