提交 8a80db80 编写于 作者: C CyrusNajmabadi

Fix regression in VB attribute classification.

上级 1bb513eb
......@@ -545,5 +545,16 @@ end sub
Await TestInClassAsync(text)
End Function
<WorkItem(21524, "https://github.com/dotnet/roslyn/issues/21524")>
<Fact, Trait(Traits.Feature, Traits.Features.Classification)>
Public Async Function TestAttribute() As Task
Await TestAsync("Imports System
<AttributeUsage()>
Class Program
End Class",
[Class]("AttributeUsage"))
End Function
End Class
End Namespace
......@@ -123,17 +123,11 @@ private static bool IsNamespaceName(NameSyntax name)
CancellationToken cancellationToken,
out ClassifiedSpan classifiedSpan)
{
if (symbol != null)
// Classify a reference to an attribute constructor in an attribute location
// as if we were classifying the attribute type itself.
if (symbol.IsConstructor() && name.IsParentKind(SyntaxKind.Attribute))
{
// see through using aliases
if (symbol.Kind == SymbolKind.Alias)
{
symbol = (symbol as IAliasSymbol).Target;
}
else if (symbol.IsConstructor() && name.IsParentKind(SyntaxKind.Attribute))
{
symbol = symbol.ContainingType;
}
symbol = symbol.ContainingType;
}
if (name.IsVar &&
......@@ -153,18 +147,15 @@ private static bool IsNamespaceName(NameSyntax name)
}
}
if (symbol != null)
// Use .Equals since we can't rely on object identity for constructed types.
if (symbol is ITypeSymbol typeSymbol)
{
// Use .Equals since we can't rely on object identity for constructed types.
if (symbol is ITypeSymbol typeSymbol)
var classification = GetClassificationForType(typeSymbol);
if (classification != null)
{
var classification = GetClassificationForType(typeSymbol);
if (classification != null)
{
var token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, classification);
return true;
}
var token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, classification);
return true;
}
}
......
......@@ -64,6 +64,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Classification.Classifiers
End Select
End If
' Classify a reference to an attribute constructor in an attribute location
' as if we were classifying the attribute type itself.
If symbol.IsConstructor() AndAlso node.IsParentKind(SyntaxKind.Attribute) Then
symbol = symbol.ContainingType
End If
If symbol IsNot Nothing Then
If symbol.Kind = SymbolKind.Method Then
Dim method = DirectCast(symbol, IMethodSymbol)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册