Skip to content

Send a /// statement whole when its continuation has a note - #371

Merged
jbearak merged 1 commit into
mainfrom
send-to-stata-noted-continuation
Nov 5, 2026
Merged

jbearak merged 1 commit into
mainfrom
send-to-stata-noted-continuation

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Send to Stata didn't follow a /// continuation with a note after it. With the cursor on reg price mpg /// controls, followed by weight, robust, it sent only the first line. Stata then ran nothing, because the do-file ended on a ///. With the cursor on the second line, it sent weight, robust alone, which fails with r(199). The detector matched only a /// at the very end of a line. A bare /// worked.

The detector now reads the document with Sight's lexer, so it follows the same // and /// rules as the language server (#367, #370). There's no text-level helper in src/ to share, and the lexer is the one place those rules live. A statement goes on to the next line when:

  • a /// with a space or tab before it, or at the start of a line, ends the line, with or without a note;
  • a /// line starts a statement (Stata reads the next line with it);
  • a token spans lines: a block comment, or a * comment continued with /// (Stata swallows the next line into the comment).

A /// in a string or a // comment doesn't continue, and neither does a tight b/// or *////. Send Upward and Send Downward Lines use the same rule.

To import the lexer, client/tsconfig.json now uses bundler module resolution instead of nodenext. Typechecking is --noEmit only, and esbuild still bundles the extension as CommonJS. The bundle grows by about 30 KB. Detection takes about 10 ms on a 20,000-line file.

Behavior changes

  • reg y x /// note, * note /// x, and a /// note line at the start of a statement now join the next line. One property test asserted the old behavior for /// note; it now asserts the join.
  • A block comment that spans lines keeps them in one statement (di "a" /* note / */ " b").
  • di "a /// (a /// in an unclosed string) and di 1 // note /// no longer join the next line. Stata doesn't join them either.
  • ends_with_continuation is gone. Its replacement is find_joined_lines(text).

Not fixed

  • Under #delimit ;, Send statement still sends only the lines joined as above, and Stata runs them under #delimit cr. The detector never followed ; statements. The docs now say to select the statement with a #delimit ; line before it.

Proof: tests/unit/send-to-stata/statement-detector.test.ts covers notes after ///, a chain of noted /// lines, /// then a blank line, /// in strings, tight ///, /// after /* */, // and * comments, statement-starting /// lines, multi-line block comments, Mata, #delimit ;, CRLF, and upward/downward bounds. 14 of its 17 tests fail on main. All four gates pass. Statements the detector extracts from the sample below, run as do-files in StataMP 18:

StataMP 18: main's detector vs. this branch

Sample:

reg price mpg /// controls
    weight, robust
reg price ///
    mpg /// first control
    weight /// second control
    , robust
summarize price /* a note */ /// then more
    mpg
* skip this /// and this
di "SWALLOWED"
===== main: cursor on line 1, sends lines 1-1
. reg price mpg /// controls
end of do-file                      (nothing ran)
===== main: cursor on line 2, sends lines 2-2
.     weight, robust
command weight is unrecognized
r(199);
===== main: cursor on line 4, sends lines 3-4
. reg price ///
>     mpg /// first control       (nothing ran)
===== main: cursor on line 6, sends lines 6-6
.     , robust
r(199);
===== main: cursor on line 7, sends lines 7-7
. summarize price /* a note */ /// then more     (nothing ran)
===== main: cursor on line 9, sends lines 9-9
. * skip this /// and this
===== fix: cursor on line 1, sends lines 1-2
. reg price mpg /// controls
>     weight, robust
Linear regression                               Number of obs     =         74
         mpg |  -49.51222    95.8074    -0.52   0.607    -240.5468    141.5223
      weight |   1.746559    .777837     2.25   0.028     .1955963    3.297522
===== fix: cursor on line 2, sends lines 1-2
  (same regression)
===== fix: cursor on line 4, sends lines 3-6
. reg price ///
>     mpg /// first control
>     weight /// second control
>     , robust
Linear regression                               Number of obs     =         74
  (mpg and weight, as above)
===== fix: cursor on line 6, sends lines 3-6
  (same regression)
===== fix: cursor on line 7, sends lines 7-8
. summarize price /* a note */ /// then more
>     mpg
       price |         74    6165.257    2949.496       3291      15906
         mpg |         74     21.2973    5.785503         12         41
===== fix: cursor on line 9, sends lines 9-10
. * skip this /// and this
> di "SWALLOWED"

Probes for the rules the tests rely on (StataMP 18): di 1 // note /// then di 2 runs both; * note /// x swallows the next line; di "A" /// then a blank line runs di "A"; x = 1 /// / + 2 in a Mata block gives 3; di "P6" /* note / */ " joined" prints P6 joined.

Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in T3 Code (Claude Code harness), reviewed by gpt-6.1-sol in Codex.

The statement detector matched only a /// at the very end of a line, so
'reg y x /// note' was sent alone. It now reads the document with Sight's
lexer, so it follows the same // and /// rules as the language server:
notes after ///, strings, block comments, // comments, tight b///, * comments
continued with ///, and statement-starting /// lines.
@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 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 6 included reviews currently available. Your 48 included PR review attempts over the past 7 days set your current allowance at 6 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: bd346700-6625-4554-a79a-d8c7ff7c8cd4
Commits

Reviewing files that changed from the base of the PR and between 85ffcaf and a6d7ee1.

Files selected for processing: 7

  • client/src/send-to-stata/index.ts
  • client/src/send-to-stata/statement-detector.ts
  • client/tsconfig.json
  • docs/send-to-stata.md
  • tests/property/helpers/mock-text-document.ts
  • tests/property/send-to-stata-statement-detection.prop.test.ts
  • tests/unit/send-to-stata/statement-detector.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit e44d5e5 into main Nov 5, 2026
14 checks passed
@jbearak
jbearak deleted the send-to-stata-noted-continuation branch November 5, 2026 03:19
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