@@ -18,7 +18,8 @@ sealed class ApiInvocationProcessor(
1818 ITypes types ,
1919 IWildcardMatcher wildcardMatcher ,
2020 Func < IFactoryApiWalker > factoryApiWalkerFactory ,
21- Func < ILocalVariableRenamingRewriter > localVariableRenamingRewriterFactory )
21+ Func < ILocalVariableRenamingRewriter > localVariableRenamingRewriterFactory ,
22+ ILocationProvider locationProvider )
2223 : IApiInvocationProcessor
2324{
2425 private static readonly char [ ] TypeNamePartsSeparators = [ '.' ] ;
@@ -96,12 +97,12 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
9697
9798 if ( symbol . TypeArguments . Length == 2 && symbol . TypeArguments is [ _, { } resultType ] )
9899 {
99- VisitFactory ( metadataVisitor , semanticModel , resultType , lambdaExpression ) ;
100+ VisitFactory ( name , metadataVisitor , semanticModel , resultType , lambdaExpression ) ;
100101 break ;
101102 }
102103 }
103104
104- VisitFactory ( metadataVisitor , semanticModel , type , lambdaExpression ) ;
105+ VisitFactory ( name , metadataVisitor , semanticModel , type , lambdaExpression ) ;
105106 break ;
106107
107108 case [ ] :
@@ -207,7 +208,7 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
207208 case nameof ( IConfiguration . RootBind ) :
208209 if ( genericName . TypeArgumentList . Arguments is not [ { } rootBindType ] )
209210 {
210- throw new CompileErrorException ( Strings . Error_InvalidRootType , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
211+ throw new CompileErrorException ( Strings . Error_InvalidRootType , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
211212 }
212213
213214 var tagArguments = invocation . ArgumentList . Arguments . SkipWhile ( ( arg , i ) => arg . NameColon ? . Name . Identifier . Text != "tags" && i < 2 ) ;
@@ -253,20 +254,20 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
253254 {
254255 case [ { Expression : LambdaExpressionSyntax lambdaExpression } ] :
255256 var factoryType = semantic . GetTypeSymbol < ITypeSymbol > ( semanticModel , implementationTypeSyntax ) ;
256- VisitFactory ( metadataVisitor , semanticModel , factoryType , lambdaExpression ) ;
257+ VisitFactory ( name , metadataVisitor , semanticModel , factoryType , lambdaExpression ) ;
257258 break ;
258259
259260 case [ { Expression : LiteralExpressionSyntax { Token . Value : string sourceCodeStatement } } ] :
260261 var lambda = SyntaxFactory
261262 . SimpleLambdaExpression ( SyntaxFactory . Parameter ( SyntaxFactory . Identifier ( "_" ) ) )
262263 . WithExpressionBody ( SyntaxFactory . IdentifierName ( sourceCodeStatement ) ) ;
263264 factoryType = semantic . GetTypeSymbol < ITypeSymbol > ( semanticModel , implementationTypeSyntax ) ;
264- VisitFactory ( metadataVisitor , semanticModel , factoryType , lambda ) ;
265+ VisitFactory ( name , metadataVisitor , semanticModel , factoryType , lambda ) ;
265266 break ;
266267
267268 case [ ] :
268269 var implementationType = semantic . GetTypeSymbol < INamedTypeSymbol > ( semanticModel , implementationTypeSyntax ) ;
269- metadataVisitor . VisitImplementation ( new MdImplementation ( semanticModel , implementationTypeSyntax , implementationType ) ) ;
270+ metadataVisitor . VisitImplementation ( new MdImplementation ( semanticModel , name , implementationType ) ) ;
270271 break ;
271272
272273 default :
@@ -291,7 +292,7 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
291292 // ReSharper disable once MergeIntoNegatedPattern
292293 || rootsType . SpecialType == Microsoft . CodeAnalysis . SpecialType . System_Object )
293294 {
294- throw new CompileErrorException ( Strings . Error_InvalidRootsRype , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
295+ throw new CompileErrorException ( Strings . Error_InvalidRootsRype , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
295296 }
296297
297298 var rootsArgs = arguments . GetArgs ( invocation . ArgumentList , "name" , "kind" , "filter" ) ;
@@ -308,15 +309,15 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
308309
309310 if ( ! hasRootsType )
310311 {
311- throw new CompileErrorException ( string . Format ( Strings . Error_Template_NoTypeForWildcard , symbolNames . GetName ( rootsType ) , rootsWildcardFilter ) , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
312+ throw new CompileErrorException ( string . Format ( Strings . Error_Template_NoTypeForWildcard , symbolNames . GetName ( rootsType ) , rootsWildcardFilter ) , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
312313 }
313314
314315 break ;
315316
316317 case nameof ( IConfiguration . Root ) :
317318 if ( genericName . TypeArgumentList . Arguments is not [ { } rootTypeSyntax ] )
318319 {
319- throw new CompileErrorException ( Strings . Error_InvalidRootType , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
320+ throw new CompileErrorException ( Strings . Error_InvalidRootType , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
320321 }
321322
322323 var rootSymbol = semantic . GetTypeSymbol < INamedTypeSymbol > ( semanticModel , rootTypeSyntax ) ;
@@ -329,7 +330,7 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
329330 // ReSharper disable once MergeIntoNegatedPattern
330331 || buildersRootType . SpecialType == Microsoft . CodeAnalysis . SpecialType . System_Object )
331332 {
332- throw new CompileErrorException ( Strings . Error_InvalidBuildersType , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
333+ throw new CompileErrorException ( Strings . Error_InvalidBuildersType , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
333334 }
334335
335336 var buildersArgs = arguments . GetArgs ( invocation . ArgumentList , "name" , "kind" , "filter" ) ;
@@ -355,15 +356,15 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
355356
356357 if ( ! hasBuildersType )
357358 {
358- throw new CompileErrorException ( string . Format ( Strings . Error_Template_NoTypeForWildcard , symbolNames . GetName ( buildersRootType ) , buildersWildcardFilter ) , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
359+ throw new CompileErrorException ( string . Format ( Strings . Error_Template_NoTypeForWildcard , symbolNames . GetName ( buildersRootType ) , buildersWildcardFilter ) , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
359360 }
360361
361362 break ;
362363
363364 case nameof ( IConfiguration . Builder ) :
364365 if ( genericName . TypeArgumentList . Arguments is not [ { } builderRootTypeSyntax ] )
365366 {
366- throw new CompileErrorException ( Strings . Error_InvalidBuilderType , name . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
367+ throw new CompileErrorException ( Strings . Error_InvalidBuilderType , locationProvider . GetLocation ( name ) , LogId . ErrorInvalidMetadata ) ;
367368 }
368369
369370 var builderType = semantic . GetTypeSymbol < INamedTypeSymbol > ( semanticModel , builderRootTypeSyntax ) ;
@@ -529,7 +530,7 @@ private IEnumerable<INamedTypeSymbol> GetRelatedTypes(
529530 var marker = types . GetMarker ( index , semanticModel . Compilation ) ;
530531 if ( marker is null )
531532 {
532- throw new CompileErrorException ( Strings . Error_TooManyTypeParameters , source . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
533+ throw new CompileErrorException ( Strings . Error_TooManyTypeParameters , locationProvider . GetLocation ( source ) , LogId . ErrorInvalidMetadata ) ;
533534 }
534535
535536 markers . Add ( marker ) ;
@@ -568,7 +569,7 @@ private void VisitBuilder(
568569 var builderLambdaExpression = ( LambdaExpressionSyntax ) SyntaxFactory . ParseExpression ( factory . ToString ( ) ) ;
569570
570571 metadataVisitor . VisitContract ( new MdContract ( semanticModel , source , builderType , ContractKind . Explicit , ImmutableArray . Create ( builderTag ) ) ) ;
571- VisitFactory ( metadataVisitor , semanticModel , builderType , builderLambdaExpression ) ;
572+ VisitFactory ( source , metadataVisitor , semanticModel , builderType , builderLambdaExpression ) ;
572573
573574 // Root
574575 metadataVisitor . VisitRoot ( new MdRoot ( source , semanticModel , builderType , builderName , builderTag , kind , invocationComments , true ) ) ;
@@ -749,6 +750,7 @@ private void VisitArg(
749750 }
750751
751752 private void VisitFactory (
753+ SyntaxNode source ,
752754 IMetadataVisitor metadataVisitor ,
753755 SemanticModel semanticModel ,
754756 ITypeSymbol resultType ,
@@ -790,7 +792,7 @@ private void VisitFactory(
790792 metadataVisitor . VisitFactory (
791793 new MdFactory (
792794 semanticModel ,
793- lambdaExpression ,
795+ source ,
794796 resultType ,
795797 localVariableRenamingRewriter ,
796798 lambdaExpression ,
@@ -1038,11 +1040,11 @@ tag is MemberAccessExpressionSyntax memberAccessExpression
10381040 return argType ?? defaultType ;
10391041 }
10401042
1041- private static void CheckNotAsync ( LambdaExpressionSyntax lambdaExpression )
1043+ private void CheckNotAsync ( LambdaExpressionSyntax lambdaExpression )
10421044 {
10431045 if ( lambdaExpression . AsyncKeyword . IsKind ( SyntaxKind . AsyncKeyword ) )
10441046 {
1045- throw new CompileErrorException ( Strings . Error_AsynchronousFactoryWithAsyncNotSupported , lambdaExpression . AsyncKeyword . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
1047+ throw new CompileErrorException ( Strings . Error_AsynchronousFactoryWithAsyncNotSupported , locationProvider . GetLocation ( lambdaExpression . AsyncKeyword ) , LogId . ErrorInvalidMetadata ) ;
10461048 }
10471049 }
10481050
@@ -1061,8 +1063,8 @@ private static void CheckNotAsync(LambdaExpressionSyntax lambdaExpression)
10611063 }*/
10621064
10631065 // ReSharper disable once SuggestBaseTypeForParameter
1064- private static void NotSupported ( SyntaxNode source ) =>
1065- throw new CompileErrorException ( string . Format ( Strings . Error_Template_NotSupported , source ) , source . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
1066+ private void NotSupported ( SyntaxNode source ) =>
1067+ throw new CompileErrorException ( string . Format ( Strings . Error_Template_NotSupported , source ) , locationProvider . GetLocation ( source ) , LogId . ErrorInvalidMetadata ) ;
10661068
10671069 private IReadOnlyList < T > BuildConstantArgs < T > (
10681070 SemanticModel semanticModel ,
@@ -1071,7 +1073,7 @@ private IReadOnlyList<T> BuildConstantArgs<T>(
10711073 . SelectMany ( a => semantic . GetConstantValues < T > ( semanticModel , a . Expression ) . Select ( value => ( value , a . Expression ) ) )
10721074 . Select ( a => a . value ?? throw new CompileErrorException (
10731075 string . Format ( Strings . Error_Template_MustBeValueOfType , a . Expression , typeof ( T ) ) ,
1074- a . Expression . GetLocation ( ) ,
1076+ locationProvider . GetLocation ( a . Expression ) ,
10751077 LogId . ErrorInvalidMetadata ) )
10761078 . ToList ( ) ;
10771079
@@ -1124,7 +1126,7 @@ private static CompositionName CreateCompositionName(
11241126 var name = nameFormatter . Format ( nameTemplate ! , type ? . OriginalDefinition , tag ) ;
11251127 if ( ! SyntaxFacts . IsValidIdentifier ( name ) )
11261128 {
1127- throw new CompileErrorException ( string . Format ( Strings . Error_Template_InvalidIdentifier , name ) , source . GetLocation ( ) , LogId . ErrorInvalidMetadata ) ;
1129+ throw new CompileErrorException ( string . Format ( Strings . Error_Template_InvalidIdentifier , name ) , locationProvider . GetLocation ( source ) , LogId . ErrorInvalidMetadata ) ;
11281130 }
11291131
11301132 return name ;
0 commit comments