Skip to content

Keep the note after /// when AST formatting instead of joining the lines and dropping it - #362

Merged
jbearak merged 3 commits into
mainfrom
ast-printer-continuation-notes
Nov 5, 2026
Merged

jbearak merged 3 commits into
mainfrom
ast-printer-continuation-notes

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

The AST formatter (formatting.mode = "ast") dropped the note after ///. It joined a continued statement onto one line and lost the comment: reg y x /// outcome first followed by z became reg y x z. This happened in commands, options, if qualifiers, = expressions, macro definitions, syntax, and the headers of if, foreach, forvalues and while blocks. The source-preserving mode was unaffected.

Now, when a /// in a statement has a note after it, the parser keeps that statement's lines as written: a brace block keeps its header through {, and an inline if keeps the whole statement. The AST printer prints those lines instead of rebuilding the statement, moving them with the statement's indentation. Statements without a noted /// print as before, so a bare /// still joins.

Re-indenting keeps meaning. After a /// with no space before it, a line at column 0 joins the token before (local a b/// then c sets bc), so such a line stays at column 0 and an indented one keeps at least one space.

Proof: reproduced the dropped notes on main; the new tests (both formatter modes, each formatted twice) fail on main and pass here; a throwaway fuzz that inserts /// note at every token gap of 28 statements (840 variants, including tight /// and nested blocks) loses the note in all 140 base variants on main, and here reparses to the same AST and formats idempotently in all but 2 (if a/// note then di 1 + 2, which joins into a body-less, brace-less if the printer already mangles on main); the four gates pass.

Reviewed with sol-loop: 3 rounds with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code); reviewed by GPT-6.1 Sol in Codex.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 38 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available. Your 37 included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 3b235ea2-ceac-4bc1-8352-a0a43c66485f
Commits

Reviewing files that changed from the base of the PR and between 83c3bc9 and 412d4b6.

Files selected for processing: 4

  • src/parser/index.ts
  • src/pretty-printer/index.ts
  • src/types/index.ts
  • tests/unit/formatter-continuation-notes.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak force-pushed the ast-printer-continuation-notes branch from 97368d5 to 945b820 Compare November 5, 2026 01:08
The AST printer joined a continued statement onto one line and dropped
the note after each `///`: `reg y x /// note` then `z` became
`reg y x z`. When a `///` in a statement has a note, the parser now
keeps the statement's lines as written (a block keeps its header
through `{`), and the printer prints them, moving each line with the
statement's indentation. Statements without a noted `///` print as
before.
…inline if

After a `///` with no space before it, a line's indentation decides
whether it joins the token before (`b///` then `c` is `bc`), so such a
line at column 0 stays there and an indented one keeps a space. The
comments after a nested inline if belong to its innermost statement;
print them too.
A `///` alone on its line keeps a tight chain going only from column 0
and after a tight `///`, as ContinuationTracker reads it. Treating any
column-0 `///` as tight made formatting change on a second pass once
it was re-indented.
@jbearak
jbearak force-pushed the ast-printer-continuation-notes branch from 945b820 to 412d4b6 Compare November 5, 2026 01:19
@jbearak
jbearak merged commit 30a7166 into main Nov 5, 2026
16 checks passed
@jbearak
jbearak deleted the ast-printer-continuation-notes branch November 5, 2026 01:24
jbearak added a commit that referenced this pull request Nov 5, 2026
Stata 18 reads `//` and `///` as a comment or a line continuation
only at the start of a line, after a space or tab, or after the `;`
that ends a statement under `#delimit ;`. Otherwise the slashes are
text: `local a b///` stores `b///` and runs the next line as its own
command, `di 4//2` is r(198), and `use http://...` opens the URL.
Sight joined `b///` to the next line (`bc`) and read any `//` as a
comment.

- Lexer: tight slashes are `/` operators; report
  CONTINUATION_NO_SPACE at a tight `///` run; drop the 7+ slash
  "visual separator" rule (Stata continues `b ////////`).
- Parser: remove ContinuationTracker and the column-0 join; a line
  break in a value is always one space. Statements with tight
  slashes keep their source lines so the AST printer neither spaces
  nor drops them.
- Formatters: remove #362's after_tight_continuation printer rule and
  #363's find_tight_continuation_lines/keep_tight_join.
- CONTINUATION_NO_SPACE is now an always-on warning, not gated by
  styleWarnings, since it changes what Stata runs.
- Send to Stata, the context tracker, and the TextMate grammar use
  the same rule.
jbearak added a commit that referenced this pull request Nov 5, 2026
…stead of joining the next line or starting a comment (#367)

* Read a // or /// with code right before it as text, as Stata does

Stata 18 reads `//` and `///` as a comment or a line continuation
only at the start of a line, after a space or tab, or after the `;`
that ends a statement under `#delimit ;`. Otherwise the slashes are
text: `local a b///` stores `b///` and runs the next line as its own
command, `di 4//2` is r(198), and `use http://...` opens the URL.
Sight joined `b///` to the next line (`bc`) and read any `//` as a
comment.

- Lexer: tight slashes are `/` operators; report
  CONTINUATION_NO_SPACE at a tight `///` run; drop the 7+ slash
  "visual separator" rule (Stata continues `b ////////`).
- Parser: remove ContinuationTracker and the column-0 join; a line
  break in a value is always one space. Statements with tight
  slashes keep their source lines so the AST printer neither spaces
  nor drops them.
- Formatters: remove #362's after_tight_continuation printer rule and
  #363's find_tight_continuation_lines/keep_tight_join.
- CONTINUATION_NO_SPACE is now an always-on warning, not gated by
  styleWarnings, since it changes what Stata runs.
- Send to Stata, the context tracker, and the TextMate grammar use
  the same rule.

* Stop file paths at a // after a space in the grammar; simplify parse-json value spacing

* Read a // after code as text when checking a program header for plugin
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.

1 participant