Add semantic classification for records#47960
Conversation
|
@CyrusNajmabadi Are there areas missing here? Colorization still doesn't seem to be working properly in some cases. I feel like this line will have to change to take in a SemanticModel so we can call GetSymbolInfo, but I think that will involve a significant amount of changes, so just want to check that this is the right move beforehand. |
| /// <summary> | ||
| /// Compares two <see cref="ISymbol"/> instances, ignoring all options | ||
| /// </summary> | ||
| public static readonly SymbolEqualityComparer IgnoreAll = new SymbolEqualityComparer(TypeCompareKind.AllIgnoreOptions); |
Nope: that's syntactic. You can determine what's going on just by checking the SyntaxKind of the containing node. IN this case syntaxKind.RecordDeclaration. |
|
|
||
| IMethodSymbol candidate = null; | ||
|
|
||
| // TO-DO: Change hard-coded '<Clone>$' to WellKnownMemberNames.CloneMethodName once it is made public |
| this.DisplayName = EditorFeaturesResources.User_Types_Records; | ||
| this.ForegroundColor = Color.FromRgb(0x2B, 0x91, 0xAF); | ||
| } | ||
| } |
There was a problem hiding this comment.
i assume this is the color for classes. i"m on the fence if i want a different color here :) might be fun to call out records as the snazzy newnews. @mikadumont for thoughts. We can possibly pick one of the safe colors we found for regexes. that would a different PR though :)
There was a problem hiding this comment.
@JoeRobich Do you need to do anything for advanced classification for this?
There was a problem hiding this comment.
@CyrusNajmabadi What do you mean by advanced classification?
There was a problem hiding this comment.
Nope. Since we are inheriting the ClassName color, there is no need to add entries to the ColorScheme files. When we decide a custom color is required we can add the entries at that time.
src/Workspaces/Core/Portable/Classification/ClassificationExtensions.cs
Outdated
Show resolved
Hide resolved
|
One question we may want to ask ourselves is whether we want the Record classification to inherit the Class color if no custom Record color is defined. This is handled by the BaseClassification attribute on the ClassificationTypeDefinition. You then wouldn't have to set a Foreground color in the EditorFormatDefintion for the User - Record Name or define colors in the ColorScheme files, since it would be inherited. Here are some things that will make this more complete. You can use this earlier PR as a guide - #31231 For classification within the Editor:
For classification within QuickInfo and SignatureHelp:
Adding a RecordName to SymbolDisplayPartKind will mean parts of Rolsyn that act on SymbolDisplayPartKind.ClassName will need to be updated such as https://github.com/dotnet/roslyn/blob/master/src/Features/Core/Portable/CodeLens/CodeLensReferencesService.cs#L258 |
…igure out why parameterized record test isn't working
|
Marking the PR as ready to review. For now, I've taken Joey's suggestion to make the default record color the same color as classes, although this can change in a follow-up PR if we decide to go with a different color. |
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitorHelpers.cs
Outdated
Show resolved
Hide resolved
|
@allisonchou @AlekseyTs here's what i think makes sense:
For all IDE features, i would want us only to use .IsRecord and never look for things like a special 'Clone' mehtod @allisonchou is this something you can pick back up? |
|
Hmm. I was about to argue that I disagree with 1, but then I realized we don't import function pointer types in VB, we just mark them as unsupported by the language, which is an observable difference between C# compilations and VB compilations. In light of that, I think I'm fine with this behavior, though I do feel like someone is going to report a bug on us for it eventually. |
Sure. But a reasoned and consistent position is fine to fall back on. :) |
|
@CyrusNajmabadi Thanks Cyrus! I've updated the code so that VB .IsRecord always returns false. |
|
@dotnet/roslyn-compiler After taking Cyrus' suggestion, I believe this PR is now once again ready for review. |
|
@dotnet/roslyn-compiler Would it be possible to get another look at this PR from the compiler side? |
|
@jcouv @AlekseyTs @333fred can you ptal at this IDE unblocker PR. Thanks! |
|
We should have some explicit tests using the |
|
Done review pass (commit 20) #Closed |
AlekseyTs
left a comment
There was a problem hiding this comment.
Changes under Compilers LGTM (iteration 22).
333fred
left a comment
There was a problem hiding this comment.
Compiler changes LGTM (commit 22)
|
Thanks everyone! |

Fixes #46985
The default color for records is the default color for classes.
https://devdiv.visualstudio.com/DevDiv/_git/VSLanguageServerClient/pullrequest/276802 will be needed to support record colorization in LSP.