Skip to content

Add Visual Basic support #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 5, 2023
Merged
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
15 changes: 9 additions & 6 deletions ScipDotnet.Tests/SnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ private Dictionary<String, SymbolInformation> SymbolTable(Document document)

private string FormatDocument(Index index, Document document)
{
var commentChar = document.Language == "C#" ? "//" : "'";
var sb = new StringBuilder();
var inputPath = new Uri(index.Metadata.ProjectRoot + "/" + document.RelativePath).LocalPath;
var occurrences = document.Occurrences.ToList();
Expand All @@ -237,7 +238,11 @@ private string FormatDocument(Index index, Document document)
var role = isDefinition ? "definition" : "reference";
var length = range.End.Character - range.Start.Character;
var indent = new String(' ', range.Start.Character);
sb.Append("//")
if (document.Language == "Visual Basic")
{
indent += " ";
}
sb.Append(commentChar)
.Append(indent)
.Append(new String('^', length))
.Append(' ')
Expand All @@ -248,7 +253,7 @@ private string FormatDocument(Index index, Document document)
if (isDefinition)
{
var info = symtab.GetValueOrDefault(occurrence.Symbol, new SymbolInformation());
var prefix = "//" + indent + new String(' ', length + 1);
var prefix = commentChar + indent + new String(' ', length + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative solution, not a request to change, just thinking out loud

``suggestion
var prefix = commentChar + indent + new String(' ', length + commentChar.length - 1);

foreach (var documentation in info.Documentation)
{
sb.Append(prefix).Append("documentation ").AppendLine(documentation.Replace("\n", "\\n"));
Expand All @@ -272,8 +277,6 @@ private string FormatDocument(Index index, Document document)
return sb.ToString();
}

private static int CompareOccurrences(Occurrence a, Occurrence b)
{
return Range.FromOccurrence(a).CompareTo(Range.FromOccurrence(b));
}
private static int CompareOccurrences(Occurrence a, Occurrence b) =>
Range.FromOccurrence(a).CompareTo(Range.FromOccurrence(b));
}
22 changes: 9 additions & 13 deletions ScipDotnet/IndexCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ public static async Task<int> Process(IHost host, List<FileInfo> projects, strin
return 0;
}

private static FileInfo OutputFile(FileInfo workingDirectory, string output)
{
return Path.IsPathRooted(output) ? new FileInfo(output) : new FileInfo(Path.Join(workingDirectory.FullName, output));
}
private static FileInfo OutputFile(FileInfo workingDirectory, string output) =>
Path.IsPathRooted(output) ? new FileInfo(output) : new FileInfo(Path.Join(workingDirectory.FullName, output));

private static async Task ScipIndex(IHost host, IndexCommandOptions options)
{
var stopwatch = Stopwatch.StartNew();
var indexer = host.Services.GetRequiredService<ScipIndexer>();
var indexer = host.Services.GetRequiredService<ScipProjectIndexer>();
var index = new Scip.Index
{
Metadata = new Metadata
Expand All @@ -71,18 +69,16 @@ private static async Task ScipIndex(IHost host, IndexCommandOptions options)
stopwatch.Elapsed.ToFriendlyString());
}

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

private static List<FileInfo> FindSolutionOrProjectFile(FileInfo workingDirectory, ILogger logger)
{
var paths = Directory.GetFiles(workingDirectory.FullName).Where(file =>
string.Equals(Path.GetExtension(file), ".sln", StringComparison.OrdinalIgnoreCase) ||
string.Equals(Path.GetExtension(file), ".csproj", StringComparison.OrdinalIgnoreCase)
string.Equals(Path.GetExtension(file), ".csproj", StringComparison.OrdinalIgnoreCase) ||
string.Equals(Path.GetExtension(file), ".vbproj", StringComparison.OrdinalIgnoreCase)
).ToList();

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

logger.LogError(
"No solution (.sln) or .csproj file detected in the working directory '{WorkingDirectory}'. {FixThis}",
"No solution (.sln) or .csproj/.vbproj file detected in the working directory '{WorkingDirectory}'. {FixThis}",
workingDirectory.FullName, FixThisProblem("SOLUTION_FILE"));
return new List<FileInfo>();
}
Expand Down
6 changes: 3 additions & 3 deletions ScipDotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static async Task<int> Main(string[] args)
{
var indexCommand = new Command("index", "Index a solution file")
{
new Argument<FileInfo>("projects", "Path to the .sln (solution) or .csproj file")
new Argument<FileInfo>("projects", "Path to the .sln (solution) or .csproj/.vbproj file")
{ Arity = ArgumentArity.ZeroOrMore },
new Option<string>("--output", () => "index.scip",
"Path to the output SCIP index file"),
Expand All @@ -43,7 +43,7 @@ public static async Task<int> Main(string[] args)
indexCommand.Handler = CommandHandler.Create(IndexCommandHandler.Process);
var rootCommand =
new RootCommand(
"SCIP indexer for the C# programming language. Built with the Roslyn .NET compiler. Supports MSBuild.")
"SCIP indexer for the C# and Visual basic programming languages. Built with the Roslyn .NET compiler. Supports MSBuild.")
{
indexCommand,
};
Expand All @@ -60,7 +60,7 @@ public static async Task<int> Main(string[] args)
host.ConfigureServices((_, collection) =>
collection
.AddSingleton(_ => CreateWorkspace())
.AddTransient<ScipIndexer>()
.AddTransient<ScipProjectIndexer>()
.AddTransient(services => (Workspace)services.GetRequiredService<MSBuildWorkspace>())
);
})
Expand Down
Loading