提交 1e3405fd 编写于 作者: B Balaji Krishnan

Do not crash when highlighting alias symbols defined via global imports.

Fixes #1904
上级 3f822cb2
......@@ -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
......
......@@ -272,5 +272,27 @@ End Class
VerifyHighlights(input)
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 Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册