@@ -76,8 +76,8 @@ private async Task<ImmutableArray<DocumentHighlights>> GetDocumentHighlightsInCu
76
76
77
77
// Get unique tags for referenced symbols
78
78
return await GetTagsForReferencedSymbolAsync (
79
- new SymbolAndProjectId ( symbol , document . Project . Id ) , documentsToSearch ,
80
- solution , cancellationToken ) . ConfigureAwait ( false ) ;
79
+ new SymbolAndProjectId ( symbol , document . Project . Id ) ,
80
+ document , documentsToSearch , cancellationToken ) . ConfigureAwait ( false ) ;
81
81
}
82
82
83
83
private static async Task < ISymbol > GetSymbolToSearchAsync ( Document document , int position , SemanticModel semanticModel , ISymbol symbol , CancellationToken cancellationToken )
@@ -95,8 +95,8 @@ private static async Task<ISymbol> GetSymbolToSearchAsync(Document document, int
95
95
96
96
private async Task < ImmutableArray < DocumentHighlights > > GetTagsForReferencedSymbolAsync (
97
97
SymbolAndProjectId symbolAndProjectId ,
98
+ Document document ,
98
99
IImmutableSet < Document > documentsToSearch ,
99
- Solution solution ,
100
100
CancellationToken cancellationToken )
101
101
{
102
102
var symbol = symbolAndProjectId . Symbol ;
@@ -106,11 +106,11 @@ private async Task<ImmutableArray<DocumentHighlights>> GetTagsForReferencedSymbo
106
106
var progress = new StreamingProgressCollector (
107
107
StreamingFindReferencesProgress . Instance ) ;
108
108
await SymbolFinder . FindReferencesAsync (
109
- symbolAndProjectId , solution , progress ,
109
+ symbolAndProjectId , document . Project . Solution , progress ,
110
110
documentsToSearch , cancellationToken ) . ConfigureAwait ( false ) ;
111
111
112
112
return await FilterAndCreateSpansAsync (
113
- progress . GetReferencedSymbols ( ) , solution , documentsToSearch ,
113
+ progress . GetReferencedSymbols ( ) , document , documentsToSearch ,
114
114
symbol , cancellationToken ) . ConfigureAwait ( false ) ;
115
115
}
116
116
@@ -142,10 +142,12 @@ private static bool ShouldConsiderSymbol(ISymbol symbol)
142
142
}
143
143
144
144
private async Task < ImmutableArray < DocumentHighlights > > FilterAndCreateSpansAsync (
145
- IEnumerable < ReferencedSymbol > references , Solution solution ,
146
- IImmutableSet < Document > documentsToSearch , ISymbol symbol ,
145
+ IEnumerable < ReferencedSymbol > references , Document startingDocument ,
146
+ IImmutableSet < Document > documentsToSearch , ISymbol symbol ,
147
147
CancellationToken cancellationToken )
148
148
{
149
+ var solution = startingDocument . Project . Solution ;
150
+
149
151
references = references . FilterToItemsToShow ( ) ;
150
152
references = references . FilterNonMatchingMethodNames ( solution , symbol ) ;
151
153
references = references . FilterToAliasMatches ( symbol as IAliasSymbol ) ;
@@ -157,13 +159,20 @@ private async Task<ImmutableArray<DocumentHighlights>> FilterAndCreateSpansAsync
157
159
158
160
var additionalReferences = new List < Location > ( ) ;
159
161
160
- foreach ( var document in documentsToSearch )
162
+ foreach ( var currentDocument in documentsToSearch )
161
163
{
162
- additionalReferences . AddRange ( await GetAdditionalReferencesAsync ( document , symbol , cancellationToken ) . ConfigureAwait ( false ) ) ;
164
+ // 'documentsToSearch' may contain documents from languages other than our own
165
+ // (for example cshtml files when we're searching the cs document). Since we're
166
+ // delegating to a virtual method for this language type, we have to make sure
167
+ // we only process the document if it's also our language.
168
+ if ( currentDocument . Project . Language == startingDocument . Project . Language )
169
+ {
170
+ additionalReferences . AddRange ( await GetAdditionalReferencesAsync ( currentDocument , symbol , cancellationToken ) . ConfigureAwait ( false ) ) ;
171
+ }
163
172
}
164
173
165
174
return await CreateSpansAsync (
166
- solution , symbol , references , additionalReferences ,
175
+ solution , symbol , references , additionalReferences ,
167
176
documentsToSearch , cancellationToken ) . ConfigureAwait ( false ) ;
168
177
}
169
178
0 commit comments