提交 f78e3f39 编写于 作者: B Balaji Krishnan

Merge pull request #2085 from balajikris/HighlightRefsAliasedSymbolsCrash

Do not crash when highlighting alias symbols defined via global imports.
...@@ -130,12 +130,17 @@ private bool ShouldConsiderSymbol(ISymbol symbol) ...@@ -130,12 +130,17 @@ private bool ShouldConsiderSymbol(ISymbol symbol)
bool addAllDefinitions = true; bool addAllDefinitions = true;
// Add definitions // Add definitions
// Filter out definitions that cannot be highlighted. e.g: alias symbols defined via project property pages.
if (symbol.Kind == SymbolKind.Alias && if (symbol.Kind == SymbolKind.Alias &&
symbol.Locations.Length > 0) 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; 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 // Add references and definitions
......
...@@ -272,5 +272,27 @@ End Class ...@@ -272,5 +272,27 @@ End Class
VerifyHighlights(input) VerifyHighlights(input)
End Sub End Sub
<WorkItem(1904, "https://github.com/dotnet/roslyn/issues/1904")>
<WorkItem(2079, "https://github.com/dotnet/roslyn/issues/2079")>
<Fact, Trait(Traits.Feature, Traits.Features.ReferenceHighlighting)>
Public Sub VerifyHighlightsForVisualBasicGlobalImportAliasedNamespace()
VerifyHighlights(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<CompilationOptions><GlobalImport>VB = Microsoft.VisualBasic</GlobalImport></CompilationOptions>
<Document>
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
</Document>
</Project>
</Workspace>)
End Sub
End Class End Class
End Namespace End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册