@@ -19,13 +19,16 @@ public CodeGraphIndexer(bool includeDataflow)
1919
2020 public async Task < IndexResult > IndexAsync ( string rootPath , CancellationToken cancellationToken )
2121 {
22- MSBuildLocator . RegisterDefaults ( ) ;
22+ if ( ! MSBuildLocator . IsRegistered && MSBuildLocator . CanRegister )
23+ {
24+ MSBuildLocator . RegisterDefaults ( ) ;
25+ }
2326 using var workspace = MSBuildWorkspace . Create ( ) ;
2427
2528 var solutionPath = FindSolution ( rootPath ) ;
2629 if ( solutionPath is not null )
2730 {
28- var solution = await workspace . OpenSolutionAsync ( solutionPath , cancellationToken ) . ConfigureAwait ( false ) ;
31+ var solution = await workspace . OpenSolutionAsync ( solutionPath , progress : null , cancellationToken ) . ConfigureAwait ( false ) ;
2932 return await BuildIndexAsync ( rootPath , solution . Projects , cancellationToken ) . ConfigureAwait ( false ) ;
3033 }
3134
@@ -35,7 +38,7 @@ public async Task<IndexResult> IndexAsync(string rootPath, CancellationToken can
3538 throw new InvalidOperationException ( "No .sln or .csproj found under the provided root." ) ;
3639 }
3740
38- var project = await workspace . OpenProjectAsync ( projectPath , cancellationToken ) . ConfigureAwait ( false ) ;
41+ var project = await workspace . OpenProjectAsync ( projectPath , progress : null , cancellationToken ) . ConfigureAwait ( false ) ;
3942 return await BuildIndexAsync ( rootPath , new [ ] { project } , cancellationToken ) . ConfigureAwait ( false ) ;
4043 }
4144
@@ -159,7 +162,11 @@ public IndexState(IReadOnlyDictionary<string, string> files)
159162 public string ToJson ( )
160163 {
161164 var payload = new IndexStatePayload { Files = new Dictionary < string , string > ( Files ) } ;
162- return System . Text . Json . JsonSerializer . Serialize ( payload , new ( ) { WriteIndented = true , PropertyNamingPolicy = System . Text . Json . JsonNamingPolicy . CamelCase } ) ;
165+ return System . Text . Json . JsonSerializer . Serialize ( payload , new System . Text . Json . JsonSerializerOptions
166+ {
167+ WriteIndented = true ,
168+ PropertyNamingPolicy = System . Text . Json . JsonNamingPolicy . CamelCase
169+ } ) ;
163170 }
164171
165172 public static IndexState FromJson ( string json )
@@ -218,6 +225,11 @@ public void AddDocument(Project project, Document document, SyntaxTree tree, Sem
218225 var root = tree . GetRoot ( ) ;
219226 foreach ( var usingDirective in root . DescendantNodes ( ) . OfType < UsingDirectiveSyntax > ( ) )
220227 {
228+ if ( usingDirective . Name is null )
229+ {
230+ continue ;
231+ }
232+
221233 var name = usingDirective . Name . ToString ( ) ;
222234 var nodeId = AddNode ( NodeKind . UsingDirective , name , document . FilePath , GetLocation ( _rootPath , usingDirective ) ) ;
223235 AddEdge ( EdgeKind . UsingDirective , documentNodeId , nodeId , GetLocation ( _rootPath , usingDirective ) ) ;
0 commit comments