Fix formatting oscillation in if-then-else branches
When a comment sits between a keyword (then/else) and certain branch
expressions (begin...end wrapping match/try/function/ifthenelse, or bare
match/try/function/ifthenelse), the comment would alternate between
"after keyword" and "before expression" placements across formatting
iterations. This caused branch_pro to compute different indentation each
time, producing "formatting did not stabilize after 10 iterations".
The fix detects these oscillation-prone patterns and ensures stable
formatting regardless of the initial comment placement:
- In Fmt_ast, when a branch matches `needs_raw_cmts_after_kw`, extract
"after keyword" comments without breaks and override branch_pro using
`Params.raw_cmts_branch_pro` (which computes mode-appropriate
break+indent+comment output).
- In Params, `branch_pro_with_cmts` detects comments "before expression"
(the alternate placement) and forces a break, producing the same layout
as the "after keyword" path.
- For begin...end branches, `branch_pro` checks for comments before the
inner expression (not just the begin...end node) to handle the case
where the comment migrates inside the begin...end scope.
Affected modes: Fit_or_vertical, Compact (profile=conventional).
Assisted-by: GitHub Copilot:claude-opus-4-20250514
af4faa
-
-
May 05 17:22 +00:00