Add records support to XmlDocCommentCompletion and ChangeSignature#53052
Add records support to XmlDocCommentCompletion and ChangeSignature#53052CyrusNajmabadi merged 22 commits intodotnet:mainfrom
Conversation
src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
Outdated
Show resolved
Hide resolved
| const int RecordDeclarationRawKind = 9063; | ||
|
|
||
| // A bit hacky to determine the parameters of primary constructor associated with a given record. | ||
| // TODO: record structs. | ||
| var primaryConstructor = recordSymbol.InstanceConstructors.FirstOrDefault( | ||
| c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax()?.RawKind == RecordDeclarationRawKind); | ||
|
|
||
| if (primaryConstructor is null) | ||
| { | ||
| return ImmutableArray<IParameterSymbol>.Empty; | ||
| } | ||
|
|
||
| return primaryConstructor.Parameters; |
There was a problem hiding this comment.
Having primary constructor with AssociatedSymbol equals to the record symbol would save this ugly workaround 😄
i.e, Be able to re-write it as recordSymbol.InstanceConstructors.FirstOrDefault(c => recordSymbol.Equals(c.AssociatedSymbol)
@jcouv @jaredpar Is this something you want to do in the compiler side?
Edit: tracked by 53092.
|
Closing and reopening: |
Is this a known issue? Re-run CI for the third time with the same error. |
| SyntaxKind.ParenthesizedLambdaExpression, | ||
| SyntaxKind.LocalFunctionStatement); | ||
| SyntaxKind.LocalFunctionStatement, | ||
| // TODO: Record structs |
There was a problem hiding this comment.
Would it be possible to create + link a work item here so we can track adding record struct support in the future?
There was a problem hiding this comment.
@allisonchou It should fall into the existing test plan issue for record structs (#51199). Tagging @jcouv to edit the issue
There was a problem hiding this comment.
we have record structs now right? so can we just add that in this PR?
| // A bit hacky to determine the parameters of primary constructor associated with a given record. | ||
| // TODO: record structs. | ||
| const int RecordDeclarationRawKind = 9063; | ||
| var potentialPrimaryCtor = typeSymbol.InstanceConstructors.FirstOrDefault( |
There was a problem hiding this comment.
Hmm, I'm a little worried about hardcoding the raw kind here. I almost think we should wait on merging until we have a proper workaround that doesn't involve hardcoding. @CyrusNajmabadi do you have any thoughts?
There was a problem hiding this comment.
we're in an abstract type, just provide a helper that C# implements, going back to source to answer this.
| } | ||
|
|
||
| // TODO: Record structs | ||
| if (updatedNode.IsKind(SyntaxKind.RecordDeclaration, out RecordDeclarationSyntax? record) && record.ParameterList is not null) |
There was a problem hiding this comment.
just don't do a kind check, and do a syntax-check, and you'll be all good here.
| if (updatedNode.IsKind(SyntaxKind.RecordDeclaration, out RecordDeclarationSyntax? record) && record.ParameterList is not null) | |
| if (updatedNode is RecordDeclarationSyntax { ParameterList: not null }) |
There was a problem hiding this comment.
@CyrusNajmabadi Nullable analysis doesn't seem to handle patterns correctly.
|
Pinging @CyrusNajmabadi and @allisonchou for review. |
allisonchou
left a comment
There was a problem hiding this comment.
Looking really good! Just have a few small comments/questions.
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/Completion/CompletionProviders/XmlDocCommentCompletionProvider.cs
Show resolved
Hide resolved
src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs
Outdated
Show resolved
Hide resolved
allisonchou
left a comment
There was a problem hiding this comment.
Thanks! This LGTM. 😄
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
Show resolved
Hide resolved
|
@Youssef1313 It looks like there's some check failures, could you take a look? |
|
@CyrusNajmabadi Can you review please? Thanks! |
| // if GetParameters extension method gets updated to handle records, we need to test EVERY usage | ||
| // of the extension method and make sure the change is applicable to all these usages. | ||
| var primaryConstructor = recordSymbol.InstanceConstructors.FirstOrDefault( | ||
| c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is RecordDeclarationSyntax); |
There was a problem hiding this comment.
consider extracting helper for this (you do the same work higher up).
| // if GetParameters extension method gets updated to handle records, we need to test EVERY usage | ||
| // of the extension method and make sure the change is applicable to all these usages. | ||
| var primaryConstructor = recordSymbol.InstanceConstructors.FirstOrDefault( | ||
| c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is RecordDeclarationSyntax); |
There was a problem hiding this comment.
used again. consider an extension now.
| else if (typeSymbol.IsRecord) | ||
| { | ||
| if (TryGetRecordPrimaryConstructor(typeSymbol, out var primaryConstructor)) | ||
| { | ||
| symbol = primaryConstructor; | ||
| } | ||
| } |
There was a problem hiding this comment.
| else if (typeSymbol.IsRecord) | |
| { | |
| if (TryGetRecordPrimaryConstructor(typeSymbol, out var primaryConstructor)) | |
| { | |
| symbol = primaryConstructor; | |
| } | |
| } | |
| else if (typeSymbol.IsRecord && TryGetRecordPrimaryConstructor(typeSymbol, out var primaryConstructor)) | |
| { | |
| symbol = primaryConstructor; | |
| } |
CyrusNajmabadi
left a comment
There was a problem hiding this comment.
lgtm. let me know if you want to add the support for record structs.
| var declaredParameters = declarationSymbol.GetParameters(); | ||
| if (declarationSymbol is INamedTypeSymbol { IsRecord: true } recordSymbol) | ||
| if (declarationSymbol is INamedTypeSymbol { IsRecord: true } recordSymbol && | ||
| recordSymbol.TryGetRecordPrimaryConstructor(out var primaryConstructor)) |
There was a problem hiding this comment.
You could move the IsRecord check into TryGetPrimaryConstructor
|
Thanks! |


The change signature part is crashing. The assertion failure is far down to the compiler layer. I wasn't able to figure out how to fix that. Tagging @allisonchou for help here since the issue was assigned to you.Figured out the reason. It's actually an existing bug (see #53089).Fixes #44558
Fixes #52738
TODOs