From 2c4b274e82ef2e42caf51d3babbf09587a6c9a9f Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Fri, 22 Nov 2024 11:23:30 -0800 Subject: [PATCH] Fix symbol display for backing fields (#76000) --- .../SymbolDisplayVisitor.Members.cs | 24 ++- .../SymbolDisplay/SymbolDisplayTests.cs | 178 +++++++++++++++++- .../Test/Symbol/Symbols/Source/RecordTests.cs | 4 +- .../Portable/CodeGen/CompilationTestData.cs | 2 +- .../SymbolDisplayCompilerInternalOptions.cs | 5 +- .../SymbolDisplay/SymbolDisplayFormat.cs | 4 +- .../SymbolDisplayVisitor.Members.vb | 18 +- .../SymbolDisplay/SymbolDisplayTests.vb | 2 +- .../QuickInfo/SemanticQuickInfoSourceTests.cs | 18 ++ 9 files changed, 227 insertions(+), 28 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index 0825bdf3f429f..0fa99aec99b2f 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -59,7 +59,15 @@ public override void VisitField(IFieldSymbol symbol) AddPunctuation(SyntaxKind.DotToken); } - if (symbol.ContainingType.TypeKind == TypeKind.Enum) + if (!Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) + && symbol is Symbols.PublicModel.FieldSymbol + && symbol.AssociatedSymbol is IPropertySymbol associatedProperty) + { + AddPropertyNameAndParameters(associatedProperty); + AddPunctuation(SyntaxKind.DotToken); + AddKeyword(SyntaxKind.FieldKeyword); + } + else if (symbol.ContainingType.TypeKind == TypeKind.Enum) { Builder.Add(CreatePart(SymbolDisplayPartKind.EnumMemberName, symbol, symbol.Name)); } @@ -321,7 +329,7 @@ public override void VisitMethod(IMethodSymbol symbol) // If we're using the metadata format, then include the return type. // Otherwise we eschew it since it is redundant in a conversion // signature. - if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames)) + if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames)) { goto default; } @@ -332,7 +340,7 @@ public override void VisitMethod(IMethodSymbol symbol) // If we're using the metadata format, then include the return type. // Otherwise we eschew it since it is redundant in a conversion // signature. - if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) || + if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) || tryGetUserDefinedOperatorTokenKind(symbol.MetadataName) == SyntaxKind.None) { goto default; @@ -462,7 +470,7 @@ public override void VisitMethod(IMethodSymbol symbol) // Note: we are using the metadata name also in the case that // symbol.containingType is null (which should never be the case here) or is an // anonymous type (which 'does not have a name'). - var name = Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) || symbol.ContainingType == null || symbol.ContainingType.IsAnonymousType + var name = Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) || symbol.ContainingType == null || symbol.ContainingType.IsAnonymousType ? symbol.Name : symbol.ContainingType.Name; @@ -476,7 +484,7 @@ public override void VisitMethod(IMethodSymbol symbol) var partKind = GetPartKindForConstructorOrDestructor(symbol); // Note: we are using the metadata name also in the case that symbol.containingType is null, which should never be the case here. - if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) || symbol.ContainingType == null) + if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) || symbol.ContainingType == null) { Builder.Add(CreatePart(partKind, symbol, symbol.Name)); } @@ -491,7 +499,7 @@ public override void VisitMethod(IMethodSymbol symbol) { AddExplicitInterfaceIfNeeded(symbol.ExplicitInterfaceImplementations); - if (!Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) && + if (!Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) && symbol.GetSymbol()?.OriginalDefinition is SourceUserDefinedOperatorSymbolBase sourceUserDefinedOperatorSymbolBase) { var operatorName = symbol.MetadataName; @@ -520,7 +528,7 @@ public override void VisitMethod(IMethodSymbol symbol) case MethodKind.UserDefinedOperator: case MethodKind.BuiltinOperator: { - if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames)) + if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames)) { Builder.Add(CreatePart(SymbolDisplayPartKind.MethodName, symbol, symbol.MetadataName)); } @@ -541,7 +549,7 @@ public override void VisitMethod(IMethodSymbol symbol) } case MethodKind.Conversion: { - if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames)) + if (Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames)) { Builder.Add(CreatePart(SymbolDisplayPartKind.MethodName, symbol, symbol.MetadataName)); } diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index 5bd36448cc083..add91eb5d5684 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -1448,7 +1448,7 @@ class C { var format = new SymbolDisplayFormat( memberOptions: SymbolDisplayMemberOptions.IncludeType, - compilerInternalOptions: SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames); + compilerInternalOptions: SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames); TestSymbolDescription( text, @@ -2049,8 +2049,10 @@ class C SymbolDisplayPartKind.Punctuation); } - [Fact] - public void TestPropertyGetAccessor() + [Theory] + [InlineData(SymbolDisplayCompilerInternalOptions.None)] + [InlineData(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames)] + internal void TestPropertyGetAccessor(SymbolDisplayCompilerInternalOptions internalOptions) { var text = @" class C { @@ -2062,6 +2064,7 @@ class C { GetMembers("get_P").Single(); var format = new SymbolDisplayFormat( + internalOptions, memberOptions: SymbolDisplayMemberOptions.IncludeAccessibility | SymbolDisplayMemberOptions.IncludeContainingType | @@ -2123,6 +2126,175 @@ class C { SymbolDisplayPartKind.Keyword); } + [Fact] + public void TestPropertyBackingField() + { + var text = @" +#nullable enable +class C { + string P { get; set; } } +"; + + Func findSymbol = global => + global.GetTypeMembers("C", 0).Single(). + GetMembers("

k__BackingField").Single(); + + var format = new SymbolDisplayFormat( + memberOptions: + SymbolDisplayMemberOptions.IncludeAccessibility | + SymbolDisplayMemberOptions.IncludeContainingType | + SymbolDisplayMemberOptions.IncludeExplicitInterface | + SymbolDisplayMemberOptions.IncludeModifiers | + SymbolDisplayMemberOptions.IncludeParameters | + SymbolDisplayMemberOptions.IncludeType); + + TestSymbolDescription( + text, + findSymbol, + format, + "private String C.P.field", + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.ClassName, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.ClassName, + SymbolDisplayPartKind.Punctuation, + SymbolDisplayPartKind.PropertyName, + SymbolDisplayPartKind.Punctuation, + SymbolDisplayPartKind.Keyword); + } + + [Fact] + public void TestPropertyBackingFieldFromCompilationReference() + { + var text = @" +#nullable enable +class C { + string P { get; set; } } +"; + + var format = new SymbolDisplayFormat( + memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeModifiers | SymbolDisplayMemberOptions.IncludeAccessibility | SymbolDisplayMemberOptions.IncludeType, + parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + + var comp1 = CreateCompilation(text); + var comp2 = CreateCompilation("", references: [comp1.ToMetadataReference()], options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All)); + + var prop = comp2.GetMember("C.

k__BackingField").GetPublicSymbol(); + var parts = SymbolDisplay.ToDisplayParts(prop, format); + + Verify( + parts, + "private string P.field", + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.PropertyName, + SymbolDisplayPartKind.Punctuation, + SymbolDisplayPartKind.Keyword); + } + + [Fact] + public void TestPropertyBackingField_UseMetadataMethodNames() + { + var text = @" +#nullable enable +class C { + string P { get; set; } } +"; + + Func findSymbol = global => + global.GetTypeMembers("C", 0).Single(). + GetMembers("

k__BackingField").Single(); + + var format = new SymbolDisplayFormat( + compilerInternalOptions: SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames, + memberOptions: + SymbolDisplayMemberOptions.IncludeAccessibility | + SymbolDisplayMemberOptions.IncludeContainingType | + SymbolDisplayMemberOptions.IncludeExplicitInterface | + SymbolDisplayMemberOptions.IncludeModifiers | + SymbolDisplayMemberOptions.IncludeParameters | + SymbolDisplayMemberOptions.IncludeType); + + TestSymbolDescription( + text, + findSymbol, + format, + "private String C.

k__BackingField", + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.ClassName, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.ClassName, + SymbolDisplayPartKind.Punctuation, + SymbolDisplayPartKind.FieldName); + } + + [Theory] + [InlineData(SymbolDisplayCompilerInternalOptions.None)] + [InlineData(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames)] + internal void TestPropertyBackingFieldFromMetadata(SymbolDisplayCompilerInternalOptions internalOptions) + { + // Metadata symbols do not associate the backing field with the property, so the metadata name is always displayed. + var text = @" +#nullable enable +class C { + string P { get; set; } } +"; + + var format = new SymbolDisplayFormat( + compilerInternalOptions: internalOptions, + memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeModifiers | SymbolDisplayMemberOptions.IncludeAccessibility | SymbolDisplayMemberOptions.IncludeType, + parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + + var comp1 = CreateCompilation(text); + var comp2 = CreateCompilation("", references: [comp1.EmitToImageReference()], options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All)); + + var prop = comp2.GetMember("C.

k__BackingField").GetPublicSymbol(); + var parts = SymbolDisplay.ToDisplayParts(prop, format); + + Verify( + parts, + "private string

k__BackingField", + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.FieldName); + } + + [Fact] + public void TestPropertyBackingFieldVB() + { + var text = @" +Class A + Public Property Prop As String +End Class"; + + var format = new SymbolDisplayFormat( + memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeModifiers | SymbolDisplayMemberOptions.IncludeAccessibility | SymbolDisplayMemberOptions.IncludeType, + parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + + var comp = CreateVisualBasicCompilation("c", text); + var a = (ITypeSymbol)comp.GlobalNamespace.GetMembers("A").Single(); + var goo = a.GetMembers("_Prop").Single(); + var parts = SymbolDisplay.ToDisplayParts(goo, format); + + Verify( + parts, + "private string _Prop", + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.FieldName); + } + [Fact] public void TestMemberEventAll() { diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs index 603c82ac99b84..f824f4e8e58a1 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/RecordTests.cs @@ -1076,11 +1076,11 @@ record C AssertEx.Equal(new[] { "System.Type! C.EqualityContract.get", "System.Type! C.EqualityContract { get; }", - "System.Int32 C.k__BackingField", + "System.Int32 C.X.field", "System.Int32 C.X { get; init; }", "System.Int32 C.X.get", "void C.X.init", - "System.String! C.k__BackingField", + "System.String! C.Y.field", "System.String! C.Y { get; init; }", "System.String! C.Y.get", "void C.Y.init", diff --git a/src/Compilers/Core/Portable/CodeGen/CompilationTestData.cs b/src/Compilers/Core/Portable/CodeGen/CompilationTestData.cs index b57b9d31da861..3797649644974 100644 --- a/src/Compilers/Core/Portable/CodeGen/CompilationTestData.cs +++ b/src/Compilers/Core/Portable/CodeGen/CompilationTestData.cs @@ -86,7 +86,7 @@ public ImmutableDictionary GetMethodsByName() private static readonly SymbolDisplayFormat _testDataKeyFormat = new SymbolDisplayFormat( compilerInternalOptions: - SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames | + SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames | SymbolDisplayCompilerInternalOptions.IncludeContainingFileForFileTypes, globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining, typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, diff --git a/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayCompilerInternalOptions.cs b/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayCompilerInternalOptions.cs index b7ecd7c4f9f6b..0acb9aa43f5fb 100644 --- a/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayCompilerInternalOptions.cs +++ b/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayCompilerInternalOptions.cs @@ -17,9 +17,10 @@ internal enum SymbolDisplayCompilerInternalOptions None = 0, ///

- /// ".ctor" instead of "Goo" + /// - ".ctor" instead of "Goo" + /// - "<Prop>k__backingField" instead of "Prop.field" (for C# backing fields) /// - UseMetadataMethodNames = 1 << 0, + UseMetadataMemberNames = 1 << 0, /// /// "List`1" instead of "List<T>" ("List(of T)" in VB). Overrides GenericsOptions on diff --git a/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayFormat.cs b/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayFormat.cs index 5e0ba2c34e6ca..20f1a5586c8b8 100644 --- a/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayFormat.cs +++ b/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayFormat.cs @@ -199,7 +199,7 @@ public class SymbolDisplayFormat SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier, compilerInternalOptions: SymbolDisplayCompilerInternalOptions.IncludeScriptType | - SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames | + SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames | SymbolDisplayCompilerInternalOptions.FlagMissingMetadataTypes | SymbolDisplayCompilerInternalOptions.IncludeCustomModifiers | SymbolDisplayCompilerInternalOptions.IncludeContainingFileForFileTypes); @@ -257,7 +257,7 @@ public class SymbolDisplayFormat miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes | SymbolDisplayMiscellaneousOptions.ExpandValueTuple, - compilerInternalOptions: SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames); + compilerInternalOptions: SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames); /// /// Used to normalize explicit interface implementation member names. diff --git a/src/Compilers/VisualBasic/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.vb b/src/Compilers/VisualBasic/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.vb index 4f872a3a02462..93acdd2c23223 100644 --- a/src/Compilers/VisualBasic/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.vb +++ b/src/Compilers/VisualBasic/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.vb @@ -199,7 +199,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic AddSpace() Case MethodKind.PropertyGet - If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then AddKeyword(SyntaxKind.FunctionKeyword) AddSpace() Else @@ -210,7 +210,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End If Case MethodKind.PropertySet - If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then AddKeyword(SyntaxKind.SubKeyword) AddSpace() Else @@ -224,7 +224,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic MethodKind.EventRemove, MethodKind.EventRaise - If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then AddKeyword(SyntaxKind.SubKeyword) AddSpace() Else @@ -245,7 +245,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim tokenKind As SyntaxKind = TryGetConversionTokenKind(symbol) - If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then AddKeyword(SyntaxKind.FunctionKeyword) AddSpace() Else @@ -259,7 +259,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Case MethodKind.UserDefinedOperator, MethodKind.BuiltinOperator Dim tokenKind As SyntaxKind = TryGetOperatorTokenKind(symbol) - If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then AddKeyword(SyntaxKind.FunctionKeyword) AddSpace() Else @@ -322,7 +322,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic MethodKind.EventRemove, MethodKind.EventRaise - If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then Builder.Add(CreatePart(SymbolDisplayPartKind.MethodName, symbol, symbol.Name, visitedParents)) Else Dim associatedPropertyOrEvent = symbol.AssociatedSymbol @@ -336,7 +336,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End If Case MethodKind.Constructor, MethodKind.StaticConstructor - If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then Builder.Add(CreatePart(SymbolDisplayPartKind.MethodName, symbol, symbol.Name, visitedParents)) Else AddKeyword(SyntaxKind.NewKeyword) @@ -346,7 +346,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim tokenKind As SyntaxKind = TryGetOperatorTokenKind(symbol) - If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then Builder.Add(CreatePart(SymbolDisplayPartKind.MethodName, symbol, symbol.Name, visitedParents)) ElseIf SyntaxFacts.IsKeywordKind(tokenKind) Then ' Prefer to add the operator token as a keyword if it considered both a keyword and an operator. @@ -361,7 +361,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Case MethodKind.Conversion Dim tokenKind As SyntaxKind = TryGetConversionTokenKind(symbol) - If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) Then + If tokenKind = SyntaxKind.None OrElse Format.CompilerInternalOptions.IncludesOption(SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) Then Builder.Add(CreatePart(SymbolDisplayPartKind.MethodName, symbol, symbol.Name, visitedParents)) Else AddKeyword(SyntaxKind.CTypeKeyword) diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb index c6a271ba02d81..5f52b065c237d 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb @@ -1552,7 +1552,7 @@ end class Dim format = New SymbolDisplayFormat( memberOptions:=SymbolDisplayMemberOptions.IncludeType, kindOptions:=SymbolDisplayKindOptions.IncludeMemberKeyword, - compilerInternalOptions:=SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames) + compilerInternalOptions:=SymbolDisplayCompilerInternalOptions.UseMetadataMemberNames) TestSymbolDescription( text, diff --git a/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs b/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs index 8b0dc9a91d517..69f27e542c324 100644 --- a/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs +++ b/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs @@ -8926,6 +8926,24 @@ void M(Person p) Documentation("The person's first name.")); } + [Fact] + public async Task QuickInfoFieldKeyword() + { + await TestWithOptionsAsync( + Options.Regular.WithLanguageVersion(LanguageVersion.Preview), + """ + class C + { + int Prop + { + get => $$field; + set => field = value; + } + } + """, +MainDescription("(field) int C.Prop.field")); + } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51615")] public async Task TestVarPatternOnVarKeyword() {