Skip to content

Fix lost and unstable comments around callbacks - #8627

Merged
cknitt merged 7 commits into
masterfrom
codex/fix-callback-comment-formatting
Sep 6, 2026
Merged

Fix lost and unstable comments around callbacks#8627
cknitt merged 7 commits into
masterfrom
codex/fix-callback-comment-formatting

Conversation

@cknitt

@cknitt cknitt commented Sep 4, 2026

Copy link
Copy Markdown
Member

Trailing comments in nested callbacks could move outward across successive formatting passes, and comments on labeled or optional callbacks could disappear. For example, formatting call(~fn=x => x /* keep */) dropped the comment.

Share the argument-span calculation between comment attachment and printing so both use the same location. An explicit fallback rule selects the regular argument layout for trailing comments and leading comments on labeled arguments, checking both the full argument and expression locations. Leading comments on unlabeled arguments retain the compact layout to preserve stability when parameter parentheses are removed. Force a line break for trailing callback line comments so they remain inside the argument list.

Share callback label printing and assemble the call document once while preserving the existing layout-specific break behavior.

Add regression coverage for labeled, optional, first, last, and nested callbacks with leading and trailing comments. The regression test checks comment text and order preservation as well as formatting stability at five print widths, reusing the parsed intermediate output.

Fixes #6976.

Validation:

  • make test-syntax
  • make test-syntax-roundtrip
  • dune exec syntax_tests
  • make checkformat
  • Exploratory audit of 2,700 argument/comment/width combinations: no comment loss or formatting instability after the fixes.
  • The final helper and test refactor introduces no snapshot changes.

Known limitation: a separate pre-existing layout instability remains at width 20 for a comment inside a braced callback body used as the first argument, such as call(x => { /* comment */ x }, value), including labeled variants.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T14:20:39.199668Z 8179a59 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ca9d2eda3

ℹ️ 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".

Comment thread CHANGELOG.md Outdated
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.58%. Comparing base (0b4bd0a) to head (8179a59).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8627   +/-   ##
=======================================
  Coverage   77.58%   77.58%           
=======================================
  Files         475      475           
  Lines       64051    64062   +11     
=======================================
+ Hits        49693    49704   +11     
  Misses      14358    14358           
Files with missing lines Coverage Δ
compiler/syntax/src/res_comments_table.ml 89.06% <100.00%> (-0.01%) ⬇️
compiler/syntax/src/res_parsetree_viewer.ml 91.42% <100.00%> (+0.07%) ⬆️
compiler/syntax/src/res_printer.ml 93.28% <100.00%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8627

@rescript/belt

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/belt@8627

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@8627

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@8627

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@8627

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@8627

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8627

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@8627

commit: 8179a59

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the codex/fix-callback-comment-formatting branch from 1b6fd4a to faabd79 Compare September 6, 2026 05:05
@cknitt

cknitt commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: faabd790b0

ℹ️ 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".

Comment thread compiler/syntax/src/res_printer.ml Outdated
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt cknitt changed the title Fix unstable formatting of trailing callback comments Fix lost and unstable comments around callbacks Sep 6, 2026
@cknitt

cknitt commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 8179a59795

ℹ️ 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".

@cknitt
cknitt requested a review from cristianoc September 6, 2026 14:23
@cknitt
cknitt merged commit 2e532c7 into master Sep 6, 2026
53 of 54 checks passed
@cknitt
cknitt deleted the codex/fix-callback-comment-formatting branch September 6, 2026 18:00
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.

Unstable formatting of comments

2 participants