44using System . Threading ;
55using System . Threading . Tasks ;
66using Microsoft . AspNetCore . Razor . Language ;
7+ using Microsoft . AspNetCore . Razor . PooledObjects ;
78using Microsoft . CodeAnalysis . ExternalAccess . Razor ;
89using Microsoft . CodeAnalysis . Razor ;
910using Microsoft . CodeAnalysis . Razor . DocumentMapping ;
@@ -30,6 +31,7 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
3031
3132 private readonly IClientCapabilitiesService _clientCapabilitiesService = args . ExportProvider . GetExportedValue < IClientCapabilitiesService > ( ) ;
3233 private readonly IWorkspaceProvider _workspaceProvider = args . WorkspaceProvider ;
34+ private readonly IFilePathService _filePathService = args . ExportProvider . GetExportedValue < IFilePathService > ( ) ;
3335
3436 protected override IDocumentPositionInfoStrategy DocumentPositionInfoStrategy => PreferAttributeNameDocumentPositionInfoStrategy . Instance ;
3537
@@ -86,6 +88,8 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
8688 return NoFurtherHandling ;
8789 }
8890
91+ using var mappedResults = new PooledArrayBuilder < SumType < VSInternalReferenceItem , LspLocation > > ( results . Length ) ;
92+
8993 // Map the C# locations back to the Razor file.
9094 foreach ( var result in results )
9195 {
@@ -100,6 +104,12 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
100104
101105 var ( mappedUri , mappedRange ) = await DocumentMappingService . MapToHostDocumentUriAndRangeAsync ( context . Snapshot , location . DocumentUri . GetRequiredParsedUri ( ) , location . Range . ToLinePositionSpan ( ) , cancellationToken ) . ConfigureAwait ( false ) ;
102106
107+ if ( _filePathService . IsVirtualCSharpFile ( mappedUri ) )
108+ {
109+ // Couldn't map, so probably a hidden part of the code-gen, let's skip it.
110+ continue ;
111+ }
112+
103113 if ( referenceItem is not null )
104114 {
105115 // Indicates the reference item is directly available in the code
@@ -118,8 +128,10 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
118128
119129 location . DocumentUri = new ( mappedUri ) ;
120130 location . Range = mappedRange . ToRange ( ) ;
131+
132+ mappedResults . Add ( result ) ;
121133 }
122134
123- return Results ( results ) ;
135+ return Results ( mappedResults . ToArrayAndClear ( ) ) ;
124136 }
125137}
0 commit comments