Skip to content

Keep strings, option arguments, call parens and blank input rows as written when formatting, and read abbreviated weights and foreach list types in parse --json - #419

Merged
jbearak merged 6 commits into
mainfrom
t3/fix-formatter-json-parse-bugs
Nov 19, 2026

Conversation

@jbearak

@jbearak jbearak commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Auditing v0.15.1..main before a stable release turned up two formatter regressions against v0.15.1, three bugs in the experimental AST formatter, and wrong structure in the new sight parse --json. Each one reproduces on main.

Default (source-preserving) formatter, regressions vs v0.15.1

  • python: text = "a;<TAB>//b": the tab in the string became three spaces. The formatter took the ; and // inside the string as Stata syntax and left them outside the embedded-code placeholder. Now it splits there only at a ; the lexer reads as ending the statement (a #delimit ; terminator, or a ; before ///), so embedded text comes back byte for byte.
  • Under #delimit ;, mpg; /// second model followed by a two-line regress: the first pass indented weight; and the indentation diagnostic flagged it, and the second pass moved it to column 0. A /// after the ; was making the next statement a continuation line. Under #delimit ; the formatter now ignores /// when deciding continuations. The ;-mode statement runs (Indent the later lines of a #delimit ; statement like the lines after ///, instead of putting them at column 0 #363) already cover the lines that really continue. One pass now gives regress mpg / weight;, with no diagnostic.

AST formatter

  • program define plug, plugin using(plugins/my.plugin) became using(plugins / my.plugin). Option arguments went through expression spacing, which also damaged other arguments that aren't expressions. On the 3,780 base ados it produced format(%9.0g) → format(9.0g), eq(#2) → eq(2), jars(libstata-plugin.jar) → jars(libstata - plugin.jar) and rspec(--&&-) → rspec(- - & & -), and saving(c:\data\x.gph) → saving(c : data x.gph). Option arguments are now printed as written. In exchange the formatter no longer adds spaces inside expression-like arguments, so eq(1,2) stays as it is.
  • display runiform() printed as display runiform, because the parser dropped empty () groups. It now keeps them. See the parser note below.
  • input x / blank row / end lost the blank row on the second pass. The printer couldn't tell one blank row from no rows, since both have empty content. It now checks whether end comes after the line where the data starts.

sight parse --json

  • summarize price [w=population]: weight words now include every abbreviation Stata 18 accepts, checked in Stata 18: weight≥w, fweight≥fw, frequency≥freq, aweight≥aw, cellsize≥cell, pweight≥pw, iweight≥iw. Matching is exact-case. [f=x], [fre=x], [cel=x] and [W=x] are r(198) in Stata and are not treated as weights.
  • foreach v of var mpg price: list_type is now varlist, with items mpg, price. Stata 18 accepts three letters or more of varlist, newlist, numlist, local and global. of va and of lo are r(198).
  • else /* note */ if 1 display 2: else_if is now true. It comes from the parser's is_else_if flag instead of the second raw token.
  • syntax [, Level(integer 95)]: default is now "95". An integer or real option's default is the number after its type. Hover shows Level(integer 95) instead of Level(integer default(95)).
  • display runiform(): args[0].text is now runiform().

Performance: formatting with inline mata:/python: lines recomputed line offsets and rebuilt the whole string for every placeholder. It now computes offsets once and makes the replacements in one pass. Indentation diagnostics on 1,000 lines of mata: x = 1 went from 11.3 ms to 2.3 ms.

Outside the formatter/CLI files: two small src/parser/index.ts changes, the empty () group and the integer/real syntax default. They invert two existing tests that asserted empty groups are dropped (tests/unit/parser.test.ts, tests/property/parenthesized-group-parsing.prop.test.ts). The hover option signature in src/providers/hover.ts changes too.

Proof: new tests in tests/unit/formatter-preserves-written-text.test.ts (both formatter modes, with a second-pass check) and tests/unit/cli/parse-graph-json.test.ts, plus an abbreviations.do golden fixture. All 11 fail on main and pass here. sight check over the 3,780 base ados gives the same diagnostics as main. Source-preserving output on those files is byte-identical to main. In AST mode 398 files change, all from the two fixes above, and the set of files that change on a second format is unchanged. check:line-endings, typecheck, bun test ./tests (9,957 pass, 0 fail) and lint each pass when run separately.

Created with Claude Opus 5.5 in Claude Code.

…rows as written, and read abbreviated weights and foreach list types in parse --json

Formatter (both modes unless noted):
- An inline python:/mata: statement whose string holds a ; before a
  comment marker ("a;\t//b") comes back byte for byte. Only a ; that
  ends the statement (a #delimit ; terminator, or a ; before ///) is
  kept outside the placeholder.
- Under #delimit ;, a /// after the ; that ends a statement no longer
  makes the next statement a continuation line, so one format reaches
  the fixed point and the indentation diagnostic agrees.
- AST mode prints option arguments as written instead of respacing
  them as expressions, which turned using(plugins/my.plugin) into
  using(plugins / my.plugin), format(%9.0g) into format(9.0g), eq(#2)
  into eq(2) and c:\data\x.gph into c : data x.gph.
- AST mode keeps the () of a call with no arguments (display
  runiform()) and a blank data row between input and end.
- Embedded-block placeholders are applied in one pass with line
  offsets computed once (1,000 mata: lines: 11.3 ms to 2.3 ms for
  indentation diagnostics).

sight parse --json:
- Weight words and abbreviations Stata 18 accepts: w..weight,
  fw..fweight, freq..frequency, aw..aweight, cell..cellsize,
  pw..pweight, iw..iweight.
- foreach ... of var/new/num/loc/glo (three letters or more) report the
  full list type.
- else /* c */ if reports else_if: true.
- syntax Level(integer 95) reports default "95"; hover shows it as
  Level(integer 95).
- display runiform() reports runiform() as its argument.
@coderabbitai

coderabbitai Bot commented Nov 19, 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 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review 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: ae493cc1-71e4-49e9-be33-1ffeab072410
Commits

Reviewing files that changed from the base of the PR and between 49213d6 and 056b9e7.

Files selected for processing: 39

  • client/src/send-to-stata/commands.ts
  • client/src/send-to-stata/console-pane.ts
  • client/src/send-to-stata/stata-terminal-manager.ts
  • client/src/send-to-stata/temp-file.ts
  • docs/cli.md
  • docs/send-to-stata.md
  • src/cli/parse-json.ts
  • src/console/automation/automation-backend.ts
  • src/console/backend.ts
  • src/console/editor-console-tty.ts
  • src/console/editor-console.ts
  • src/console/pty-backend.ts
  • src/console/session-host.ts
  • src/console/session.ts
  • src/expression-parser/index.ts
  • src/formatter/alignment-detector.ts
  • src/formatter/indentation-analyzer.ts
  • src/lexer/index.ts
  • src/parser/index.ts
  • src/pretty-printer/index.ts
  • src/providers/formatter.ts
  • src/providers/hover.ts
  • src/utils/program-definition.ts
  • tests/fixtures/cli-json/expected/graph.json
  • tests/fixtures/cli-json/expected/parse.json
  • tests/fixtures/cli-json/project/abbreviations.do
  • tests/integration/client-console-bundle.test.ts
  • tests/integration/send-to-stata-integrated-terminal.test.ts
  • tests/property/parenthesized-group-parsing.prop.test.ts
  • tests/unit/brace-block-bodies.test.ts
  • tests/unit/cli/json-golden.test.ts
  • tests/unit/cli/parse-graph-json.test.ts
  • tests/unit/console/automation-backend.test.ts
  • tests/unit/console/session.test.ts
  • tests/unit/formatter-preserves-written-text.test.ts
  • tests/unit/input-data-edge-cases.test.ts
  • tests/unit/parser-release-audit-regressions.test.ts
  • tests/unit/parser.test.ts
  • tests/unit/send-to-stata/temp-file.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak force-pushed the t3/fix-formatter-json-parse-bugs branch from 1f88e50 to 4dda092 Compare November 19, 2026 14:45
jbearak and others added 5 commits November 19, 2026 09:50
…] as Stata does, and keep label/note text and program-header comments when formatting (#417)

Fixes parser regressions since v0.15.1, each checked against StataMP 18:

- include/do/run using/setup.do takes the path, not the using keyword
- program `cmdname' defines a program closed by its end
- #delimit ; program // note, then define p; defines p
- `stem'using, `stem'in and `stem'if are one name
- price[`weight'] is a subscript, not a weight clause
- label variable/data/define, char and note ...: text keeps its
  if/in/using words, and AST formatting prints it as written
- a comment in a program header, or a /// note before an inline
  mata:, makes AST formatting leave the file as written instead of
  dropping it
- a run of // comments in a #delimit ; statement parses in linear time
…g, or behind a long command, and keep polling after a huge burst of output (#416)

* Keep the Stata console polling after a huge burst of output, and keep editor sends from being lost at --more--, while connecting, or behind a long command

- Automation backend: append a poll's lines without spreading them
  (a burst of ~200k lines overflowed the stack and stopped polling for
  good), consume held lines by index, and keep polling after a poll
  throws, saying so once.
- Editor sends go through a new send_line entry (console API v3): at
  --more-- they wait for the prompt instead of being taken as pager
  keys; typed keys still answer --more--.
- A Stata pane holds each typed send's temp file until its console
  gives the line to Stata, then deletes it after the usual delay; it
  deletes it at once if the line is dropped or the pane ends.
- The active-terminal commands send to a Stata pane through its queue,
  so a send made while the pane connects isn't dropped.

* Don't let a hand-off's cleanup delete a send's file soon after the pane releases it
…tar comments as Stata does (#414)

* Read input data, prefixed embedded openers, and #delimit ; star comments as Stata does

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bound the program-header check to the input data region

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Test formatting of prefixed mata: lines and #delimit ; input records

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Test a * comment after an abbreviated #d ;

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
The blank-row check compared line numbers, which under #delimit ; is
true for an empty block because the data starts on the input line.
Caught by input-data-edge-cases.test.ts once main's #414 was merged in.
@jbearak
jbearak merged commit 1c22bfb into main Nov 19, 2026
16 checks passed
@jbearak
jbearak deleted the t3/fix-formatter-json-parse-bugs branch November 19, 2026 15:04
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