From 1e3405fd773cd68825b992441f3c125e04148a84 Mon Sep 17 00:00:00 2001 From: Balaji Krishnan Date: Fri, 17 Apr 2015 13:57:47 -0700 Subject: [PATCH] Do not crash when highlighting alias symbols defined via global imports. Fixes #1904 --- .../AbstractDocumentHighlightsService.cs | 9 ++++++-- .../VisualBasicReferenceHighlightingTests.vb | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Core/Implementation/ReferenceHighlighting/AbstractDocumentHighlightsService.cs b/src/EditorFeatures/Core/Implementation/ReferenceHighlighting/AbstractDocumentHighlightsService.cs index 1dd9dc4d54b..0d847ff5fc2 100644 --- a/src/EditorFeatures/Core/Implementation/ReferenceHighlighting/AbstractDocumentHighlightsService.cs +++ b/src/EditorFeatures/Core/Implementation/ReferenceHighlighting/AbstractDocumentHighlightsService.cs @@ -130,12 +130,17 @@ private bool ShouldConsiderSymbol(ISymbol symbol) bool addAllDefinitions = true; // Add definitions + // Filter out definitions that cannot be highlighted. e.g: alias symbols defined via project property pages. if (symbol.Kind == SymbolKind.Alias && symbol.Locations.Length > 0) { - // For alias symbol we want to get the tag only for the alias definition, not the target symbol's definition. - await AddLocationSpan(symbol.Locations.First(), solution, spanSet, tagMap, HighlightSpanKind.Definition, cancellationToken).ConfigureAwait(false); addAllDefinitions = false; + + if (symbol.Locations.First().IsInSource) + { + // For alias symbol we want to get the tag only for the alias definition, not the target symbol's definition. + await AddLocationSpan(symbol.Locations.First(), solution, spanSet, tagMap, HighlightSpanKind.Definition, cancellationToken).ConfigureAwait(false); + } } // Add references and definitions diff --git a/src/EditorFeatures/Test2/ReferenceHighlighting/VisualBasicReferenceHighlightingTests.vb b/src/EditorFeatures/Test2/ReferenceHighlighting/VisualBasicReferenceHighlightingTests.vb index 955310e4766..878578000ca 100644 --- a/src/EditorFeatures/Test2/ReferenceHighlighting/VisualBasicReferenceHighlightingTests.vb +++ b/src/EditorFeatures/Test2/ReferenceHighlighting/VisualBasicReferenceHighlightingTests.vb @@ -272,5 +272,27 @@ End Class VerifyHighlights(input) End Sub + + + + + Public Sub VerifyHighlightsForVisualBasicGlobalImportAliasedNamespace() + VerifyHighlights( + + + VB = Microsoft.VisualBasic + + Class Test + Public Sub TestMethod() + ' Add reference tags to verify after #2079 is fixed + Console.Write(NameOf($$VB)) + Console.Write(NameOf(VB)) + Console.Write(NameOf(Microsoft.VisualBasic)) + End Sub + End Class + + + ) + End Sub End Class End Namespace -- GitLab