Repository navigation
Conversation
dae0442 to
cc7571e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## parsetree-spread #8906 +/- ##
=================================================
Coverage 81.20% 81.20%
=================================================
Files 458 458
Lines 63933 63957 +24
=================================================
+ Hits 51918 51938 +20
- Misses 12015 12019 +4
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc7571ef6f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| | Indent doc -> has_ungrouped_line_suffix doc | ||
| | IfBreaks {yes; no} -> | ||
| has_ungrouped_line_suffix yes || has_ungrouped_line_suffix no | ||
| | Group _ | Nil | Text _ | LineBreak _ | BreakParent -> false |
There was a problem hiding this comment.
Handle grouped suffixes without a later break
A Group does not guarantee that breaking it will encounter a LineBreak after its line suffix. For example, print_object_get_doc produces a group containing parent_doc; "[\"member\"]"; with an operand such as switch obj // c\n["member"] { ... }, the comment is attached to obj, but there is no break after that suffix inside the group. Returning false here prevents print_operand_before_brace from adding protective parentheses, and the inserted BreakParent only changes the mode—it does not flush the queued suffix—so the comment still prints after the following { and continues relocating on subsequent formats.
Useful? React with 👍 / 👎.
cc7571e to
1ebd43e
Compare
1ebd43e to
621783f
Compare
Why:
A line comment inside the operand of switch, try, if, while or a loop
was printed as a line suffix in a flat group, so it moved behind the
opening brace, and the next format attached it to the block.
The operand now breaks the groups around such a comment, and a comment
trailing the whole operand goes into parentheses with it, as if conditions
already did.
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.
Area: printer tests
Output: unchanged
Formatting: changed operands of switch, try, if, while and loops that
contain a line comment; 80 operand/comment combinations format
idempotently (48 did not before), and 330 spread contexts format as before
apart from those
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>
621783f to
cfa5e3e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Stacked on #8905.
A line comment inside the operand of
switch,try,if,whileor a loop moved behind the opening brace when the formatter kept the operand on one line, and the next format attached it to the block, so the output changed on every run:The comment is printed as a line suffix in a flat group. Operands followed by a block now force the groups around such a comment to break (
Doc.break_before_line_suffixes). A comment trailing the whole operand, which no group break can move, goes into parentheses with the operand, asifconditions already did:Making every same-line line comment break its group would also fix this, but it reformats stable code such as
foo(v :> b) // comment(3 snapshot changes), so the change is limited to operands before a block.Checked with a harness of 10 operand positions × 8 operand/comment shapes: all 80 now format idempotently (48 did not before). A 330-case differential of other contexts formats as before apart from the comment-in-operand cases.
New test:
printer/comments/operandBeforeBlock.res.🤖 Generated with Claude Code
https://claude.ai/code/session_01EUpL6dKCiSwAeriDGRHqNr