-
Notifications
You must be signed in to change notification settings - Fork 439
Fix CodeGenerationFormat
to correctly indent LabeledExprListSyntax
in method calls that start on a new line
#2851
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 CodeGenerationFormat
to correctly indent LabeledExprListSyntax
in method calls that start on a new line
#2851
Conversation
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.
Nice, just a syntactic comment. The approach looks good to me
let inMethodCallThatStartsOnNewline = | ||
if let functionCallExpr = node.parent?.as(FunctionCallExprSyntax.self), | ||
let memberAccessExpr = functionCallExpr.calledExpression.as(MemberAccessExprSyntax.self), | ||
startsOnNewline(memberAccessExpr.period) | ||
{ | ||
true | ||
} else { | ||
false | ||
} |
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.
If you mad startsOnNewline
an extension on SyntaxProtocol
this could be done without an if
expression:
node.parent?.as(FunctionCallExprSyntax.self).calledExpression.as(MemberAccessExprSyntax.self)?.startsOnNewline ?? false
Why does this only apply if the called expression is a MemberAccessExprSyntax
? Shouldn’t the same be true for top level function calls as well?
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.
If you mad
startsOnNewline
an extension onSyntaxProtocol
this could be done without anif
expression:node.parent?.as(FunctionCallExprSyntax.self).calledExpression.as(MemberAccessExprSyntax.self)?.startsOnNewline ?? false
Done 👍
Why does this only apply if the called expression is a
MemberAccessExprSyntax
? Shouldn’t the same be true for top level function calls as well?
If you mean top level function calls by specifying the module, they also parse into MemberAccessExprSyntax
. Example:
Swift
.print(
"1",
"2",
separator: ",",
terminator: ";"
)

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 mean if you have something like
print(
"1",
"2"
)
Or do we format that correctly already?
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.
Or do we format that correctly already?
Yes we do.
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.
Oh, great. Thanks for confirming
Should I squash the commits to remove the use of the |
Yes, that would be good |
…` in method calls that start on a new line
9676296
to
0dcb6df
Compare
Done 👍 |
@swift-ci Please test |
@swift-ci Please test |
@swift-ci Please test Windows |
1 similar comment
@swift-ci Please test Windows |
This fixes a case where
CodeGenerationFormat
would incorrectly indent the arguments (LabeledExprListSyntax
) and the right parenthesis of method calls that start on a new line when formatting children to be separated by a newline.