-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add records support to XmlDocCommentCompletion and ChangeSignature #53052
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Pinging @CyrusNajmabadi and @allisonchou for review. |
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.
Looking really good! Just have a few small comments/questions.
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
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
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if (typeSymbol.IsRecord) | |
{ | |
if (TryGetRecordPrimaryConstructor(typeSymbol, out var primaryConstructor)) | |
{ | |
symbol = primaryConstructor; | |
} | |
} | |
else if (typeSymbol.IsRecord && TryGetRecordPrimaryConstructor(typeSymbol, out var primaryConstructor)) | |
{ | |
symbol = primaryConstructor; | |
} |
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.
lgtm. let me know if you want to add the support for record structs.
@@ -369,21 +369,10 @@ private string GetAttributeValue(XmlAttributeSyntax attribute) | |||
protected override ImmutableArray<IParameterSymbol> GetParameters(ISymbol declarationSymbol) | |||
{ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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