-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix Function Pointer RefKind Display #51223
Merged
333fred
merged 12 commits into
dotnet:main
from
YairHalberstadt:fix-function-pointer-display
Mar 17, 2021
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9c99cbc
Fix Function Pointer Display
YairHalberstadt a3f324d
SignatureOnlyParameterSymbol.ContainingSymbol throws
YairHalberstadt ad7ddea
Fix broken test
YairHalberstadt 04b0378
Changes based on review by @alekseyts and @333fred
YairHalberstadt ef0d6cc
don't check for function pointer at all in SymbolDisplayVisitor.Visit…
YairHalberstadt d31a3dc
Fix broken tests, and address feedback from @AlekseyTs
YairHalberstadt cfbe45c
check for empty name instead of function pointer symbol in VisitParam…
YairHalberstadt 9799b7d
rename variable from includeOption to includeDefaultValue
YairHalberstadt 6f6e883
unconditionally display ref kinds for function pointers
YairHalberstadt e3f11f5
Fix couple of broken tests
YairHalberstadt 18f2bde
Merge branch 'main' of https://github.com/dotnet/roslyn into fix-func…
YairHalberstadt cb03900
Fix tests
YairHalberstadt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -609,18 +609,25 @@ void visitFunctionPointerSignature(IMethodSymbol symbol) | |
|
||
foreach (var param in symbol.Parameters) | ||
{ | ||
param.Accept(this.NotFirstVisitor); | ||
AddParameterRefKind(param.RefKind); | ||
|
||
AddCustomModifiersIfRequired(param.RefCustomModifiers); | ||
|
||
param.Type.Accept(this.NotFirstVisitor); | ||
|
||
AddCustomModifiersIfRequired(param.CustomModifiers, leadingSpace: true, trailingSpace: false); | ||
|
||
AddPunctuation(SyntaxKind.CommaToken); | ||
AddSpace(); | ||
} | ||
|
||
if (symbol.ReturnsByRef) | ||
{ | ||
AddRefIfRequired(); | ||
AddRef(); | ||
} | ||
else if (symbol.ReturnsByRefReadonly) | ||
{ | ||
AddRefReadonlyIfRequired(); | ||
AddRefReadonly(); | ||
} | ||
|
||
AddCustomModifiersIfRequired(symbol.RefCustomModifiers); | ||
|
@@ -679,9 +686,13 @@ public override void VisitParameter(IParameterSymbol symbol) | |
// used on their own or in the context of methods. | ||
|
||
var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); | ||
var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) | ||
&& !(symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }); | ||
var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && | ||
symbol.Name.Length != 0; | ||
var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); | ||
var includeDefaultValue = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && | ||
format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && | ||
symbol.HasExplicitDefaultValue && | ||
CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue); | ||
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. With the latest changes to how function pointers are printed, are any of these changes to |
||
|
||
if (includeBrackets && symbol.IsOptional) | ||
{ | ||
|
@@ -703,26 +714,26 @@ public override void VisitParameter(IParameterSymbol symbol) | |
AddCustomModifiersIfRequired(symbol.CustomModifiers, leadingSpace: true, trailingSpace: false); | ||
} | ||
|
||
if (includeName && includeType) | ||
{ | ||
AddSpace(); | ||
} | ||
|
||
if (includeName) | ||
{ | ||
if (includeType) | ||
{ | ||
AddSpace(); | ||
} | ||
var kind = symbol.IsThis ? SymbolDisplayPartKind.Keyword : SymbolDisplayPartKind.ParameterName; | ||
builder.Add(CreatePart(kind, symbol, symbol.Name)); | ||
} | ||
|
||
if (format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && | ||
symbol.HasExplicitDefaultValue && | ||
CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue)) | ||
if (includeDefaultValue) | ||
{ | ||
if (includeName || includeType) | ||
{ | ||
AddSpace(); | ||
AddPunctuation(SyntaxKind.EqualsToken); | ||
AddSpace(); | ||
|
||
AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue); | ||
} | ||
AddPunctuation(SyntaxKind.EqualsToken); | ||
AddSpace(); | ||
|
||
AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue); | ||
} | ||
|
||
if (includeBrackets && symbol.IsOptional) | ||
|
@@ -936,22 +947,32 @@ private void AddRefIfRequired() | |
{ | ||
if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) | ||
{ | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
AddRef(); | ||
} | ||
} | ||
|
||
private void AddRef() | ||
{ | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
} | ||
|
||
private void AddRefReadonlyIfRequired() | ||
{ | ||
if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) | ||
{ | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
AddKeyword(SyntaxKind.ReadOnlyKeyword); | ||
AddSpace(); | ||
AddRefReadonly(); | ||
} | ||
} | ||
|
||
private void AddRefReadonly() | ||
{ | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
AddKeyword(SyntaxKind.ReadOnlyKeyword); | ||
AddSpace(); | ||
} | ||
|
||
private void AddReadOnlyIfRequired() | ||
{ | ||
// 'readonly' in this context is effectively a 'ref' modifier | ||
|
@@ -967,21 +988,26 @@ private void AddParameterRefKindIfRequired(RefKind refKind) | |
{ | ||
if (format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeParamsRefOut)) | ||
{ | ||
switch (refKind) | ||
{ | ||
case RefKind.Out: | ||
AddKeyword(SyntaxKind.OutKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.Ref: | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.In: | ||
AddKeyword(SyntaxKind.InKeyword); | ||
AddSpace(); | ||
break; | ||
} | ||
AddParameterRefKind(refKind); | ||
} | ||
} | ||
|
||
private void AddParameterRefKind(RefKind refKind) | ||
{ | ||
switch (refKind) | ||
{ | ||
case RefKind.Out: | ||
AddKeyword(SyntaxKind.OutKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.Ref: | ||
AddKeyword(SyntaxKind.RefKeyword); | ||
AddSpace(); | ||
break; | ||
case RefKind.In: | ||
AddKeyword(SyntaxKind.InKeyword); | ||
AddSpace(); | ||
break; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It appears an extra empty line was added above this line. Could be an issue with the diff tool though. #Closed