Skip to content

Commit

Permalink
Optimize and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
tcz717 committed Jan 16, 2022
1 parent 9eb1319 commit 73cf1d1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 26 deletions.
6 changes: 3 additions & 3 deletions LsifDotnet/Lsif/LsifIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public async IAsyncEnumerable<LsifItem> EmitLsif()
Debug.Assert(quickInfoService != null, nameof(quickInfoService) + " != null");
Console.WriteLine("Document {0}", document.Name);

var identifierVisitor = new IdentifierVisitor();
var identifierVisitor = new CSharpIdentifierVisitor();
identifierVisitor.Visit(await document.GetSyntaxRootAsync());

foreach (var token in identifierVisitor.IdentifierList)
{
var symbol = await SymbolFinder.FindSymbolAtPositionAsync(document, token.SpanStart);
var location = token.GetLocation();
var linePositionSpan = location.GetMappedLineSpan();

if (!location.IsInSource)
{
Expand All @@ -83,11 +84,10 @@ public async IAsyncEnumerable<LsifItem> EmitLsif()
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (symbol is null)
{
Console.WriteLine($"Symbol not found {token.Value}");
Console.WriteLine($"Symbol not found {token.Value} at {linePositionSpan}");
continue;
}

var linePositionSpan = location.GetMappedLineSpan();
var rangeVertex = new RangeVertex(NextId(), linePositionSpan);
ranges.Add(rangeVertex.Id);
yield return rangeVertex;
Expand Down
6 changes: 0 additions & 6 deletions LsifDotnet/MarkdownHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public static class MarkdownHelper
/// </summary>
private const string ContainerEnd = nameof(ContainerEnd);

public static bool StartsWithNewline(this ImmutableArray<TaggedText> taggedParts)
{
return !taggedParts.IsDefaultOrEmpty
&& taggedParts[0].Tag switch { TextTags.LineBreak => true, ContainerStart => true, _ => false };
}

public static string TaggedTextToMarkdown(
ImmutableArray<TaggedText> taggedParts,
MarkdownFormat markdownFormat)
Expand Down
15 changes: 1 addition & 14 deletions LsifDotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,18 @@
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.NamingConventionBinder;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using LsifDotnet.Lsif;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis.MSBuild;
using QuikGraph;
using QuikGraph.Graphviz;

namespace LsifDotnet;

/// <summary>
/// Test
/// </summary>
class Program
{
/// <summary>
/// Test
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
static async Task Main(string[] args)
{
var rootCommand = new RootCommand("An indexer that dumps lsif information from dotnet solution.")
Expand All @@ -37,7 +24,7 @@ static async Task Main(string[] args)
new Option<FileInfo>("--output", () => new FileInfo("dump.lsif"),
"The lsif dump output file."),
new Option<bool>("--dot", "Dump graphviz dot file."),
new Option<bool>("--svg", "Dump graph svg file."),
new Option<bool>("--svg", "Dump graph svg file. (by quickchart.io/graphviz API)"),
new Option<CultureInfo>("--culture", () => CultureInfo.CurrentUICulture,
"The culture used to show hover info."),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace LsifDotnet.Roslyn;

public class IdentifierVisitor : CSharpSyntaxWalker
public class CSharpIdentifierVisitor : CSharpSyntaxWalker
{
public List<SyntaxToken> IdentifierList { get; set; } = new List<SyntaxToken>();
public List<SyntaxToken> IdentifierList { get; set; } = new();

public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Visit https://lsif.dev/ to learn about LSIF.

Example scenario:[Sourcegraph precise code intelligence](https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence) ([lsif-dotnet repo](https://sourcegraph.com/github.com/tcz717/LsifDotnet/-/blob/LsifDotnet/Program.cs)
Example scenario: [Sourcegraph precise code intelligence](https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence) ([lsif-dotnet repo](https://sourcegraph.com/github.com/tcz717/LsifDotnet/-/blob/LsifDotnet/Program.cs))


Only tested in win platform and don't support `VisualBasic` yet.
Expand Down

0 comments on commit 73cf1d1

Please sign in to comment.