-
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
Changes from 3 commits
8305017
6d6f087
41eae46
ac6de34
6fbf876
76c88dc
4c0bcef
df2d615
6749276
aa0c17d
e494608
e8ac91d
a7c5f11
d36653a
de681db
0c8bfef
42bf97a
b7ca33c
761c811
43eb33e
149d578
327b8e2
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 |
---|---|---|
|
@@ -124,6 +124,19 @@ internal async Task<ChangeSignatureAnalyzedContext> GetChangeSignatureContextAsy | |
{ | ||
symbol = typeSymbol.DelegateInvokeMethod; | ||
} | ||
else if (typeSymbol.IsRecord) | ||
{ | ||
// A bit hacky to determine the parameters of primary constructor associated with a given record. | ||
// TODO: record structs. | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const int RecordDeclarationRawKind = 9063; | ||
var potentialPrimaryCtor = typeSymbol.InstanceConstructors.FirstOrDefault( | ||
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. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think #53092 may not be very soon 😕 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. we're in an abstract type, just provide a helper that C# implements, going back to source to answer this. |
||
c => c.DeclaringSyntaxReferences.FirstOrDefault().GetSyntax()?.RawKind == RecordDeclarationRawKind); | ||
|
||
if (potentialPrimaryCtor is not null) | ||
{ | ||
symbol = potentialPrimaryCtor; | ||
} | ||
} | ||
} | ||
|
||
if (!symbol.MatchesKind(SymbolKind.Method, SymbolKind.Property)) | ||
|
@@ -1001,7 +1014,6 @@ protected ImmutableArray<SyntaxTrivia> GetPermutedDocCommentTrivia(Document docu | |
node.GetTrailingTrivia(), | ||
lastWhiteSpaceTrivia, | ||
document.Project.Solution.Options.GetOption(FormattingOptions.NewLine, document.Project.Language)); | ||
|
||
var newTrivia = Generator.Trivia(extraDocComments); | ||
|
||
updatedLeadingTrivia.Add(newTrivia); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,13 +364,33 @@ public static bool IsParams([NotNullWhen(returnValue: true)] this ISymbol? symbo | |
} | ||
|
||
public static ImmutableArray<IParameterSymbol> GetParameters(this ISymbol? symbol) | ||
=> symbol switch | ||
{ | ||
return symbol switch | ||
{ | ||
IMethodSymbol m => m.Parameters, | ||
IPropertySymbol nt => nt.Parameters, | ||
IPropertySymbol p => p.Parameters, | ||
INamedTypeSymbol nt when nt.IsRecord => GetRecordParameters(nt), | ||
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. yeah, i do not like this at all. i'd say the caller needs to potentially deal with records. 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. @CyrusNajmabadi Done. However, it became a little bit more complicated. |
||
_ => ImmutableArray<IParameterSymbol>.Empty, | ||
}; | ||
|
||
ImmutableArray<IParameterSymbol> GetRecordParameters(INamedTypeSymbol recordSymbol) | ||
{ | ||
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; | ||
} | ||
} | ||
|
||
public static ImmutableArray<ITypeParameterSymbol> GetTypeParameters(this ISymbol? symbol) | ||
=> symbol switch | ||
{ | ||
|
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have record structs now right? so can we just add that in this PR?