@@ -151,11 +151,12 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
151151 context . SemanticModel ,
152152 ct ) )
153153 . WithTrackingName ( "ConsoleApp.Builder.0_CreateSyntaxProvider" )
154- . Where ( x =>
154+ . Select ( ( x , ct ) =>
155155 {
156156 var model = x . Model . GetTypeInfo ( ( x . Node . Expression as MemberAccessExpressionSyntax ) ! . Expression , x . CancellationToken ) ;
157- return model . Type ? . Name is "ConsoleAppBuilder" or "IHostBuilder" || model . Type ? . Kind == SymbolKind . ErrorType ; // allow ErrorType(ConsoleAppBuilder from Configure***(Source Generator generated method) is unknown in Source Generator)
157+ return ( x , model . Type ? . Name , model . Type ? . Kind ) ;
158158 } )
159+ . Where ( x => x . Name is "ConsoleAppBuilder" or "IHostBuilder" || x . Kind == SymbolKind . ErrorType ) // allow ErrorType(ConsoleAppBuilder from Configure***(Source Generator generated method) is unknown in Source Generator)
159160 . WithTrackingName ( "ConsoleApp.Builder.1_Where" )
160161 . Collect ( )
161162 . Combine ( generatorOptions )
@@ -353,7 +354,7 @@ class CollectBuilderContext : IEquatable<CollectBuilderContext>
353354 FilterInfo [ ] ? globalFilters { get ; }
354355 ConsoleAppFrameworkGeneratorOptions generatorOptions { get ; }
355356
356- public CollectBuilderContext ( ConsoleAppFrameworkGeneratorOptions generatorOptions , ImmutableArray < BuilderContext > contexts , CancellationToken cancellationToken )
357+ public CollectBuilderContext ( ConsoleAppFrameworkGeneratorOptions generatorOptions , ImmutableArray < ( BuilderContext , string ? , SymbolKind ? ) > contexts , CancellationToken cancellationToken )
357358 {
358359 this . DiagnosticReporter = new DiagnosticReporter ( ) ;
359360 this . CancellationToken = cancellationToken ;
@@ -362,19 +363,24 @@ public CollectBuilderContext(ConsoleAppFrameworkGeneratorOptions generatorOption
362363 // validation, invoke in loop is not allowed.
363364 foreach ( var item in contexts )
364365 {
365- if ( item . Name is "Run" or "RunAsync" ) continue ;
366- foreach ( var n in item . Node . Ancestors ( ) )
366+ var ( ctx , name , kind ) = item ;
367+ if ( kind == SymbolKind . ErrorType ) continue ; // ErrorType can't distinguished from ConsoleAppFramework or others so ignore all.
368+
369+ if ( ctx . Name is "Run" or "RunAsync" ) continue ;
370+ foreach ( var n in ctx . Node . Ancestors ( ) )
367371 {
368372 if ( n . Kind ( ) is SyntaxKind . WhileStatement or SyntaxKind . DoStatement or SyntaxKind . ForStatement or SyntaxKind . ForEachStatement )
369373 {
370- DiagnosticReporter . ReportDiagnostic ( DiagnosticDescriptors . AddInLoopIsNotAllowed , item . Node . GetLocation ( ) ) ;
374+ DiagnosticReporter . ReportDiagnostic ( DiagnosticDescriptors . AddInLoopIsNotAllowed , ctx . Node . GetLocation ( ) ) ;
371375 return ;
372376 }
373377 }
374378 }
375379
376- var methodGroup = contexts . ToLookup ( x =>
380+ var methodGroup = contexts . ToLookup ( ctx =>
377381 {
382+ var x = ctx . Item1 ;
383+
378384 if ( x . Name == "Add" && ( ( x . Node . Expression as MemberAccessExpressionSyntax ) ? . Name . IsKind ( SyntaxKind . GenericName ) ?? false ) )
379385 {
380386 return "Add<T>" ;
@@ -384,6 +390,7 @@ public CollectBuilderContext(ConsoleAppFrameworkGeneratorOptions generatorOption
384390 } ) ;
385391
386392 globalFilters = methodGroup [ "UseFilter" ]
393+ . Select ( x => x . Item1 )
387394 . OrderBy ( x => x . Node . GetLocation ( ) . SourceSpan ) // sort by line number
388395 . Select ( x =>
389396 {
@@ -413,6 +420,7 @@ public CollectBuilderContext(ConsoleAppFrameworkGeneratorOptions generatorOption
413420
414421 var names = new HashSet < string > ( ) ;
415422 var commands1 = methodGroup [ "Add" ]
423+ . Select ( x => x . Item1 )
416424 . Select ( x =>
417425 {
418426 var wellKnownTypes = new WellKnownTypes ( x . Model . Compilation ) ;
@@ -432,6 +440,7 @@ public CollectBuilderContext(ConsoleAppFrameworkGeneratorOptions generatorOption
432440 . ToArray ( ) ; // evaluate first.
433441
434442 var commands2 = methodGroup [ "Add<T>" ]
443+ . Select ( x => x . Item1 )
435444 . SelectMany ( x =>
436445 {
437446 var wellKnownTypes = new WellKnownTypes ( x . Model . Compilation ) ;
0 commit comments