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 2cf5866
Browse filesBrowse the repository at this point in the historyBrowse files
Place five kinds of comments where they were written when formatting
Why:
Five cases from #9107 put comments or doc comments in a different
place, and one of them changed the attribute order in the AST. A
single hugged parameter with a doc comment, or a callback parameter
with one, was printed with its pattern at column 0. A comment after
the `)` of a `switch`, `if`, `while`, loop or `try` operand was not
adjacent to the operand, so it went into the block. The tail spread
of a list printed its leading comments after the dots. Doc comments
after an attribute were moved in front of all attributes. A file with
only a line comment got an extra newline.
A comment now records whether a `)` precedes it, and the operand of
a block construct also keeps the comments after its closing
parentheses that come before the block. A doc comment stays in front
of the attributes only when it already was, so later ones print in
their place.
Format modified (doc comment on a hugged parameter):
Example:
let f = (/** r */ {x, y}) => x
Before (rescript):
let f = (/** r */
{x, y}) => x
After (rescript):
let f = (
/** r */
{x, y},
) => x
Format modified (comment after a parenthesized operand):
Example:
let v = switch (x) // c1
{ | 1 => 2 | _ => 3 }
Before (rescript):
let v = switch x {
// c1
| 1 => 2
| _ => 3
}
After (rescript):
let v = switch (
x // c1
) {
| 1 => 2
| _ => 3
}
Format modified (comment before a list's tail spread):
Example:
let l = list{1, /* c */ ...xs}
Before (rescript):
let l = list{1, .../* c */ xs}
After (rescript):
let l = list{1, /* c */ ...xs}
AST modified (doc comment after an attribute, after formatting):
Example:
type u = /** d1 */ @A /** d2 */ {x: int}
Before (parse):
type_declaration "u"
attribute "res.doc"
attribute "res.doc"
attribute "a"
After (parse):
type_declaration "u"
attribute "res.doc"
attribute "a"
attribute "res.doc"
Format modified (file with only a line comment):
Example:
// c
Before (text): "// c\n\n"
After (text): "// c\n"
Review: Can a `)` inside the block be taken for the operand's? No: only
comments that end before the first case, the `then` branch or the body,
attributes included, are considered.
Fixes: #9107
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP
Signed-off-by: Christoph Knittel <ck@cca.io>
- Fix the formatter's placement of doc comments on hugged or callback parameters and after attributes, of comments after a parenthesized `switch`/`if`/loop operand or before a list's tail spread, and the extra newline after a file with only a line comment.
0 commit comments