-
Notifications
You must be signed in to change notification settings - Fork 148
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
Allow single-line if
expressions
#648
base: main
Are you sure you want to change the base?
Conversation
e4fc755
to
51a20b7
Compare
51a20b7
to
a4c2d98
Compare
Note: I have not found a more optimized solution than the 3 |
14298af
to
bb3f1c2
Compare
if
expressionsif
expressions
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.
Thanks for taking this on!
This will need more tests. Specifically an example of all the different single/multiline combinations should be added to tests/test-files/good/Elm-0.19/AllSyntax/Expressions.elm
(probably in or immediately after ifStatement
(line 273)).
I totally agree this needs more tests, but I need some guidance because I don't understand if tests in |
Ah, So for this PR:
|
This comment has been minimized.
This comment has been minimized.
bb3f1c2
to
67161e6
Compare
31f33b7
to
e83afa4
Compare
e83afa4
to
c541461
Compare
c541461
to
12f4095
Compare
e4f3518
to
7ee8a14
Compare
I think that the PR is now complete, including tests. |
@@ -0,0 +1 @@ | |||
x = if True then 1 else if False then 2 else 3 |
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.
👍
src/ElmFormat/Render/Box.hs
Outdated
] | ||
|
||
(_, ifCond, thenBody, _, elseBody) -> | ||
formatIfExpressionMultiline elmVersion importInfo ifCond thenBody elseifs elseBody |
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.
The way these two functions work together seems a bit complicated. The ideal is that these functions basically have two phases: 1) turning all the stuff into boxes and 2) assembling the boxes based on the multiline features. Here we turn just enough into boxes to decide if we should call the other function, which makes it a bit harder to follow the full logic.
Though looking at the code for a few minutes, I don't have any quick suggestions of how to refactor this, so if you don't have time to give a try to simplifying this more, that's fine. (A lot of the existing code in here is way more confusing than this)
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 it should be easier to follow the logic now.
Looks great, thanks! I'll let you know when I get And also I think this will start the 0.9 releases as a notable behavior change. |
dafb82b
to
d0ec5dc
Compare
Left box -> box | ||
|
||
|
||
boxesOrLinesToBox :: Bool -> Either [Box] [Line] -> Box |
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.
Maybe we could put this function and boxOrLineToBox
into Box.hs
?
I'm not sure because of the use of ElmStructure.forceableSpaceSepOrStack1
.
d0ec5dc
to
d9404ad
Compare
Really looking forward to this feature. I feel like this would clean up a bunch of code the previously required lots of space |
Resolves #209