-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
SwitchExpression formatting. #237
Comments
Oh wow.... I think I like the line breaking strategy of # 2 overall, but I think we shouldn't break at all if the whole statement fits in one line. |
Good point, it would probably look nice for some switch expressions, but for this one would end up with lines that are way too long.
Are you thinking each individual statement of the switch wouldn't break unless it gets too long? Or that if any of the individual statements of the switch break then they all break? |
Another example of a big switch expression, which may change how we decide to format these. return node switch
{
InvocationExpressionSyntax
or ParenthesizedLambdaExpressionSyntax
or ObjectCreationExpressionSyntax
or ElementAccessExpressionSyntax
or ArrayCreationExpressionSyntax
or ImplicitArrayCreationExpressionSyntax => Doc.Group(
Doc.GroupWithId(groupId, Doc.Indent(Doc.Line)),
Doc.IndentIfBreak(Doc.Group(Node.Print(node)), groupId)
),
InitializerExpressionSyntax when node.Kind()
is SyntaxKind.CollectionInitializerExpression => Doc.Group(
Doc.Line,
Node.Print(node)
),
AnonymousObjectCreationExpressionSyntax
or AnonymousMethodExpressionSyntax
or InitializerExpressionSyntax
or ConditionalExpressionSyntax
or SwitchExpressionSyntax
or LambdaExpressionSyntax
or AwaitExpressionSyntax
or WithExpressionSyntax => Doc.Group(
Doc.Group(Doc.Indent(Doc.Line)),
Node.Print(node)
),
BinaryExpressionSyntax
or InterpolatedStringExpressionSyntax
or IsPatternExpressionSyntax
or LiteralExpressionSyntax
or QueryExpressionSyntax
or StackAllocArrayCreationExpressionSyntax => Doc.Indent(
Doc.Group(Doc.Line, Node.Print(node))
),
_ => Doc.Group(Doc.Indent(Doc.Line), Doc.Indent(Node.Print(node)))
};
// Looks pretty decent as
InvocationExpressionSyntax
or ParenthesizedLambdaExpressionSyntax
or ObjectCreationExpressionSyntax
or ElementAccessExpressionSyntax
or ArrayCreationExpressionSyntax
or ImplicitArrayCreationExpressionSyntax
=> Doc.Group(
Doc.GroupWithId(groupId, Doc.Indent(Doc.Line)),
Doc.IndentIfBreak(Doc.Group(Node.Print(node)), groupId)
),
InitializerExpressionSyntax when node.Kind()
is SyntaxKind.CollectionInitializerExpression
=> Doc.Group(
Doc.Line,
Node.Print(node)
),
AnonymousObjectCreationExpressionSyntax
or AnonymousMethodExpressionSyntax
or InitializerExpressionSyntax
or ConditionalExpressionSyntax
or SwitchExpressionSyntax
or LambdaExpressionSyntax
or AwaitExpressionSyntax
or WithExpressionSyntax
=> Doc.Group(
Doc.Group(Doc.Indent(Doc.Line)),
Node.Print(node)
),
BinaryExpressionSyntax
or InterpolatedStringExpressionSyntax
or IsPatternExpressionSyntax
or LiteralExpressionSyntax
or QueryExpressionSyntax
or StackAllocArrayCreationExpressionSyntax
=> Doc.Indent(
Doc.Group(Doc.Line, Node.Print(node))
),
_ => Doc.Group(Doc.Indent(Doc.Line), Doc.Indent(Node.Print(node)))
}; |
* Better formatting for switch expressions closes #237 * Fixing some edge cases
The text was updated successfully, but these errors were encountered: