Fix formatting instability on long if conditions with if-then-else=fit-or-vertical#2797
Open
MisterDA wants to merge 2 commits intoocaml-ppx:mainfrom
Open
Fix formatting instability on long if conditions with if-then-else=fit-or-vertical#2797MisterDA wants to merge 2 commits intoocaml-ppx:mainfrom
if-then-else=fit-or-vertical#2797MisterDA wants to merge 2 commits intoocaml-ppx:mainfrom
Conversation
…then
When using if-then-else=fit-or-vertical, a comment placed between the
`then` keyword and the branch expression caused an infinite oscillation
between two formats:
then (* comment *) <--> then
expr (* comment *)
expr
The root cause is that the hovbox's soft break (break 1 2) in branch_pro
allows the comment to fit on the same line as `then` when the hovbox
doesn't break. On re-parsing, the comment is then classified as 'after
the then keyword' instead of 'before the expression', producing a
different layout that breaks back to the other form.
Fix: in the Fit_or_vertical case, when comments exist before the branch
body and the overall expression is multi-line, force a hard line break
(break 1000 2) so the comment always stays on its own indented line.
The single-line check ensures short expressions that fit on one line
are unaffected.
Add a test case with a long condition and a comment between `then` and the branch expression. This is the pattern that previously triggered 'formatting did not stabilize after 10 iterations' with if-then-else=fit-or-vertical.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I vibe-clauded a fix for #2770, which is an annoying blocker for me.