-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Use common logic for printing rhs of assignment expressions #324
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.
Looks good, just the potential change to put the brace on a new line for collection initializers that break.
@@ -62,8 +62,7 @@ class ClassName | |||
var collectionInitializerExpressions = new SomeObject | |||
{ | |||
ThisIsACollection = { one, two }, | |||
ThisIsAlsoACollection = | |||
{ | |||
ThisIsAlsoACollection = { |
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 think we want to keep the old formatting on this, but your change does get this consistent with arrayInitializerWithoutSize
above it. It could also be a new issue.
node.Right is InitializerExpressionSyntax ? Doc.Null : " ", | ||
Node.Print(node.Right) | ||
) | ||
RightHandSide.Print(node.Right) |
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.
👍 for reusing the code from VariableDeclaration in here
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.
More pattern matching magic can make this code more magical... 🧙♂️ 🌟
or LambdaExpressionSyntax | ||
or AwaitExpressionSyntax | ||
or WithExpressionSyntax | ||
? FormatMode.NoIndent |
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 looks like a nested ternary if on type matches. Usually, a switch statement looks better.
Not sure how good it will look with a dozen or
s. But if it doesn't look good you can probably split them into multiple arms of the switch.
|
||
private static Doc IndentIfNeeded(ExpressionSyntax initializerValue, FormatMode formatMode) | ||
{ | ||
if (formatMode is FormatMode.NoIndent) |
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 think this whole function could be replaced by an expression bodied method with a single switch statement. Up to you if you think this code looks better though.
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.
👍
public static Doc Print(ExpressionSyntax node) | ||
{ | ||
var groupId = Guid.NewGuid().ToString(); | ||
return node 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.
This gives us another good test case for #237.
Updates #37