-
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
Format pointers to have asterisk next to type instead of identifier #49875
Conversation
if (currentToken.Kind() == SyntaxKind.AsteriskToken && currentToken.Parent is PointerTypeSyntax) | ||
{ | ||
return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine); | ||
} | ||
|
||
if (previousToken.Kind() == SyntaxKind.AsteriskToken && | ||
(previousToken.Parent is PrefixUnaryExpressionSyntax || previousToken.Kind() == SyntaxKind.IdentifierToken)) |
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.
NOTE: The original issue complains about NormalizeWhitespace, I'm not sure whether this affects NormalizeWhitespace or not.
The number of failing tests is large. So I'd like to have a review on the code change before fixing the tests. |
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.
This implementation change affects the formatter, which is completely unrelated code from NormalizeWhitespace
.
(previousToken.Kind() == SyntaxKind.AsteriskToken && previousToken.Parent is PrefixUnaryExpressionSyntax)) | ||
if (currentToken.Kind() == SyntaxKind.AsteriskToken && currentToken.Parent is PointerTypeSyntax) | ||
{ | ||
return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine); |
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.
❗ I believe this will break the formatter for types like int**
(it will start to format them as int* *
.
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.
@sharwell Do we want to fix both the formatter and NormalizeWhitespace
? or only NormalizeWhitespace
?
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.
shouldn't we always adjust this to 0 spaces if we have the *
of a pointer type? i would think we would always want zero spaces between that and whatever comes before it
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.
@CyrusNajmabadi Whops, I mixed things up. Swapped the expected behavior and the actual behavior.
The formatter behaves as expected. This is only a NormalizeWhitespace issue.
Closing the PR.
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.
Change seems wrong. also, missing tests.
Fixes #49733