-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix Quick Info nullability display for backing fields #77240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ca0d59
b53cbee
d47fdd0
110c6a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2164,6 +2164,121 @@ class C { | |
| SymbolDisplayPartKind.Keyword); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/77219")] | ||
| public void TestPropertyBackingField_Minimal_01() | ||
| { | ||
| var text = @" | ||
| #nullable enable | ||
| class C { | ||
| string P { get; set; } } | ||
| "; | ||
|
|
||
| Func<NamespaceSymbol, Symbol> findSymbol = global => | ||
| global.GetTypeMembers("C", 0).Single(). | ||
| GetMembers("<P>k__BackingField").Single(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no better way to do this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't an API on the IPropertySymbol that gives us the backing field, for example, so I don't think there are particularly better ways to do this in general.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe there's an issue asking for this. The ide has wanted such an associated symbol API since forever :-) Note, what you can do instead is get all the fields and they get the single one associated with the property of interest. |
||
|
|
||
| var format = new SymbolDisplayFormat( | ||
| memberOptions: | ||
| SymbolDisplayMemberOptions.IncludeExplicitInterface); | ||
|
|
||
| TestSymbolDescription( | ||
| text, | ||
| findSymbol, | ||
| format, | ||
| "P.field", | ||
| SymbolDisplayPartKind.PropertyName, | ||
| SymbolDisplayPartKind.Punctuation, | ||
| SymbolDisplayPartKind.Keyword); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/77219")] | ||
| public void TestPropertyBackingField_Minimal_02() | ||
| { | ||
| var text = @" | ||
| #nullable enable | ||
|
|
||
| interface I { | ||
| string P { get; set; } | ||
| } | ||
|
|
||
| class C : I { | ||
| string I.P { get; set; } } | ||
| "; | ||
|
|
||
| Func<NamespaceSymbol, Symbol> findSymbol = global => | ||
| global.GetTypeMembers("C", 0).Single(). | ||
| GetMembers("<I.P>k__BackingField").Single(); | ||
|
|
||
| var format = new SymbolDisplayFormat( | ||
| memberOptions: | ||
| SymbolDisplayMemberOptions.IncludeExplicitInterface); | ||
|
|
||
| TestSymbolDescription( | ||
| text, | ||
| findSymbol, | ||
| format, | ||
| "I.P.field", | ||
| SymbolDisplayPartKind.InterfaceName, | ||
| SymbolDisplayPartKind.Punctuation, | ||
| SymbolDisplayPartKind.PropertyName, | ||
| SymbolDisplayPartKind.Punctuation, | ||
| SymbolDisplayPartKind.Keyword); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/77219")] | ||
| public void TestPropertyBackingField_Minimal_03() | ||
| { | ||
| var text = @" | ||
| #nullable enable | ||
|
|
||
| interface I { | ||
| string P { get; set; } | ||
| } | ||
|
|
||
| class C : I { | ||
| string I.P { get; set; } } | ||
| "; | ||
|
|
||
| Func<NamespaceSymbol, Symbol> findSymbol = global => | ||
| global.GetTypeMembers("C", 0).Single(). | ||
| GetMembers("<I.P>k__BackingField").Single(); | ||
|
|
||
| var format = new SymbolDisplayFormat(); | ||
|
|
||
| TestSymbolDescription( | ||
| text, | ||
| findSymbol, | ||
| format, | ||
| "P.field", | ||
| SymbolDisplayPartKind.PropertyName, | ||
| SymbolDisplayPartKind.Punctuation, | ||
| SymbolDisplayPartKind.Keyword); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/77219")] | ||
| public void TestOrdinaryField_Minimal() | ||
| { | ||
| var text = @" | ||
| #nullable enable | ||
|
|
||
| class C { | ||
| string F; | ||
| "; | ||
|
|
||
| Func<NamespaceSymbol, Symbol> findSymbol = global => | ||
| global.GetTypeMembers("C", 0).Single(). | ||
| GetMembers("F").Single(); | ||
|
|
||
| var format = new SymbolDisplayFormat(); | ||
|
|
||
| TestSymbolDescription( | ||
| text, | ||
| findSymbol, | ||
| format, | ||
| "F", | ||
| SymbolDisplayPartKind.FieldName); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TestPropertyBackingFieldFromCompilationReference() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raw string plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. this is a compiler test. up to you.