You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b149637
Browse filesBrowse the repository at this point in the historyBrowse files
Keep line comments in operands followed by a block
Why:
#9061 keeps a line comment in the operand of switch, try, if, while or a
loop by putting the operand into parentheses when
Doc.has_pending_line_suffix finds the comment still queued at its end.
A comment after an item or argument then moves to the end of the
operand, away from the item it describes.
The operand now first breaks the groups around such a comment
(Doc.break_before_line_suffixes), so the comment stays after its item and
the parentheses are only needed when it is still pending. A binary
expression is left flat: breaking it would flush the comment after the
operator, where the next format attaches it to the right operand, so it
keeps #9061's parentheses.
Format modified (line comment in a switch operand):
Example:
let x = switch [
a, // c
b,
] {
| _ => 1
}
Before (rescript):
let x = switch (
[a, b] // c
) {
| _ => 1
}
After (rescript):
let x = switch [
a, // c
b,
] {
| _ => 1
}
Review: Why not make every same-line line comment break its group? That changes code that formats stably today, such as foo(v :> b) // comment, which would split over three lines; the drift only happens before a block.
Review: Why are binary operands exempt? With their group broken, `switch a // c\n+ b {` printed `a + // c\nb` and then `a +\n// c\nb` on the next format; flat, it prints `switch (\n a + b // c\n) {` and stays.
Area: printer tests
Output: unchanged
Formatting: operands of switch, try, if, while and loops with a line comment
after an item or argument keep it there; binary operands keep #9061's
parentheses
Formats: none
PPX: unchanged
Editor: unchanged
Tests: +tests/syntax_tests/data/printer/comments/operandBeforeBlock.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EUpL6dKCiSwAeriDGRHqNr
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
- Keep a line comment after an item or argument in the operand of `switch`, `try`, `if`, `while` or a loop next to that item when formatting, instead of moving it to the end of the operand.
0 commit comments