-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
Revisit if/then/else #2334
Revisit if/then/else #2334
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!
Looks great (from PR description) Should |
This never came up in Fantomas or the style guide so I don't think the community is really waiting for that setting. If enough interest is expressed in the style guide we could have this, but for now, it feels like we can do without it. I'll start raising a PR for the style guide to capture what is implemented here. Once that lands I'll finish up this PR. |
@@ -442,6 +443,26 @@ let a = [1;2;3] | |||
let b = [|4;5;6|] | |||
``` | |||
|
|||
### fsharp_max_if_then_short_width |
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.
@yisusalanpng keep in mind that I added this documentation bit to the old docs.
Please move it as well in #2336
This PR introduces the
fsharp_max_if_then_short_width
setting from #2299 and revisits longifExpr
andmatchExpr
(See fsharp/fslang-design#646 (comment)).My personal interest is more in the latter, as it is quite satisfying how much more consistently we deal with these situations.
The flow is the following:
First
if x then
is printed, if it fits on the rest of the line it stays in one line.If it cross the
max_line_length
boundary or is multiline it changes toIf the entire expression is lower than the
fsharp_max_if_then_short_width
, it stays in one line.Otherwise, it will put the
thenExpr
on the next line:The default value for this is 0, so out of the box, it will always format this on multiple lines.
The same flow applies when there is an
elseExpr
, how there the existingfsharp_max_if_then_else_short_width
setting is used there.In case there are any
elif
branches, we check if every line is short. If so, we apply the short style otherwise the long one. Again, what happens inside thethenExpr
will be respected.The same flow applies if there is an
elseExpr
, however, in there we use thefsharp_max_if_then_else_short_width
length.The same principle applies to
match
andmatch!
expressions:The nice thing is that
x
can be formatted the exact same way it would be as a standalone expression. This is because of the relaxations in F# 6 and sparks a lot of joy for this maintainer.The story overall makes a lot more sense when we do the multiline thing for
ifExpr
ormatchExpr
.@dsyme what do you think about this?
@dawedawe would you mind reviewing this?