Skip to content

Additional fixes on top of #2810 - #2815

Merged
Julow merged 3 commits into
ocaml-ppx:mainfrom
yakobowski:fix-2810-standalone
Jul 29, 2026
Merged

Additional fixes on top of #2810#2815
Julow merged 3 commits into
ocaml-ppx:mainfrom
yakobowski:fix-2810-standalone

Conversation

@yakobowski

Copy link
Copy Markdown
Contributor

This MR fixes a few additional problems for the if-then-else=fit-or-vertical mode. It is stacked on top of #2180.

The first commit partially reverts some changes (bare_branch logic) in order to fix some additional less-than-ideal reformatting found on our codebase. I have added testcases, but I was not able to add the more interesting ones in a standalone commit, as ocamlformat without the fix does not stabilize in some configurations. (See the last commit.)

Boris Yakobowski and others added 3 commits July 29, 2026 17:06
When a comment precedes a parenthesized match/try/function/if branch
(janestreet and ahrefs profiles with parens_ite or exp_grouping=parens),
glue the opening paren to the content instead of putting it alone on a
line.  Before: `(* cmt *)\n(\nmatch e with\n| ...)`
After:  `(* cmt *)\n(match e with\n | ...)`

Also simplify raw_cmts_branch_pro: remove the bare_branch distinction
(always emit trailing break), since paren-glue now handles the case that
bare_branch was partially covering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests the paren-glue behavior: with exp_grouping=parens (janestreet,
ahrefs), [begin match ... end] is parsed as a bare match needing
parenthesization; a preceding comment must not glue to the opening
paren.

Without the fix, this renders as:
    (* a comment *)begin match some_long_scrutinee_expression with
                   | A -> a
                   | B -> b
                   end
or (with exp_grouping=parens):
    (* a comment *)
    (
    match some_long_scrutinee_expression with
    | A -> a
    | B -> b)

Note: without the preceding fix, janestreet + k-r mode has a
pre-existing over-indentation issue for match-in-parens branches (match
indented +2 relative to the comment inside the parens).  This caused
non-convergence with max-iters=3 in the unfixed code; the paren-glue
fix resolves the oscillation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Julow
Julow force-pushed the fix-2810-standalone branch from 0ef5647 to 77a3b23 Compare July 29, 2026 15:07

@Julow Julow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I took the liberty to rebase on top of #2810 and #2818 and to push on your branch.

@Julow
Julow merged commit 8ee0c21 into ocaml-ppx:main Jul 29, 2026
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants