提交 e32ef2d2 编写于 作者: C CyrusNajmabadi

Fix crash in DocHighlights when delegating to a different language.

上级 8d1d7ae2
......@@ -76,8 +76,8 @@ internal abstract partial class AbstractDocumentHighlightsService : IDocumentHig
// Get unique tags for referenced symbols
return await GetTagsForReferencedSymbolAsync(
new SymbolAndProjectId(symbol, document.Project.Id), documentsToSearch,
solution, cancellationToken).ConfigureAwait(false);
new SymbolAndProjectId(symbol, document.Project.Id),
document, documentsToSearch, cancellationToken).ConfigureAwait(false);
}
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
private async Task<ImmutableArray<DocumentHighlights>> GetTagsForReferencedSymbolAsync(
SymbolAndProjectId symbolAndProjectId,
Document document,
IImmutableSet<Document> documentsToSearch,
Solution solution,
CancellationToken cancellationToken)
{
var symbol = symbolAndProjectId.Symbol;
......@@ -106,11 +106,11 @@ private static async Task<ISymbol> GetSymbolToSearchAsync(Document document, int
var progress = new StreamingProgressCollector(
StreamingFindReferencesProgress.Instance);
await SymbolFinder.FindReferencesAsync(
symbolAndProjectId, solution, progress,
symbolAndProjectId, document.Project.Solution, progress,
documentsToSearch, cancellationToken).ConfigureAwait(false);
return await FilterAndCreateSpansAsync(
progress.GetReferencedSymbols(), solution, documentsToSearch,
progress.GetReferencedSymbols(), document, documentsToSearch,
symbol, cancellationToken).ConfigureAwait(false);
}
......@@ -142,10 +142,12 @@ private static bool ShouldConsiderSymbol(ISymbol symbol)
}
private async Task<ImmutableArray<DocumentHighlights>> FilterAndCreateSpansAsync(
IEnumerable<ReferencedSymbol> references, Solution solution,
IImmutableSet<Document> documentsToSearch, ISymbol symbol,
IEnumerable<ReferencedSymbol> references, Document document,
IImmutableSet<Document> documentsToSearch, ISymbol symbol,
CancellationToken cancellationToken)
{
var solution = document.Project.Solution;
references = references.FilterToItemsToShow();
references = references.FilterNonMatchingMethodNames(solution, symbol);
references = references.FilterToAliasMatches(symbol as IAliasSymbol);
......@@ -157,13 +159,20 @@ private static bool ShouldConsiderSymbol(ISymbol symbol)
var additionalReferences = new List<Location>();
foreach (var document in documentsToSearch)
foreach (var additionalDocument in documentsToSearch)
{
additionalReferences.AddRange(await GetAdditionalReferencesAsync(document, symbol, cancellationToken).ConfigureAwait(false));
// 'documentsToSearch' may contain documents from languages other than our own
// (for example cshtml files when we're searching the cs document). Since we're
// delegating to a virtual method for this language type, we have to make sure
// we only process the document if it's also our language.
if (additionalDocument.Project.Language == document.Project.Language)
{
additionalReferences.AddRange(await GetAdditionalReferencesAsync(document, symbol, cancellationToken).ConfigureAwait(false));
}
}
return await CreateSpansAsync(
solution, symbol, references, additionalReferences,
solution, symbol, references, additionalReferences,
documentsToSearch, cancellationToken).ConfigureAwait(false);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册