Skip to content

Send a #delimit ; statement whole, and run it under #delimit ; - #372

Merged
jbearak merged 1 commit into
mainfrom
send-to-stata-delimit-semicolon
Nov 5, 2026
Merged

jbearak merged 1 commit into
mainfrom
send-to-stata-delimit-semicolon

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Send to Stata didn't know about #delimit ;. With the cursor in a ; region, Send statement sent one line, or only the lines joined by ///. Every send also runs as a do-file that starts under #delimit cr. So di "A"; failed with "A; invalid name", reg price / mpg weight; ran as two broken commands, and a selected ; block failed with r(198). Send selection and Send Downward Lines had the same gap.

Now, in a ; region, Send statement sends the whole statement up to its ;, across as many lines as it takes. The detector gets this from the lexer's delimiter state and SemicolonStatementTracker, so #370's column-0 ////// rules hold. When the sent code starts in a ; region (Send statement, a selection, or Send Downward Lines), it gets a #delimit ; line first. StataMP 18 goes back to #delimit cr when a do or include file ends, so nothing is appended. A trailing #delimit cr would be swallowed by an unterminated statement. Send File and Send Upward Lines start at line 1, so they already carry the file's own #delimit lines.

Behavior

  • Comment lines just before a ; statement are sent with it. A comment after a ; (di "A"; // note) doesn't pull the next statement in with it.
  • // c / // d / di "x"; is one statement, so it gives r(199) when sent, as it does when the file runs.
  • A block's header (foreach v in a b {;), each body line, and }; are separate statements, as under #delimit cr. A selected block runs whole.
  • A mata; … end; block is one statement, as the lexer reads it.
  • A selection that starts on or before the #delimit ; line carries it and gets no prefix. One that starts after it gets the prefix.

Code changes

  • statement-detector.ts: read_document lexes once and returns the joined lines and the #delimit directives. The new find_code_to_send picks the code for each send mode and adds the prefix, so it's testable without vscode. commands.ts calls it.
  • Two integration-test mock editors lacked selection.start, which a real Selection has. They now include it.

Not changed

  • Send statement on a block header still sends only the header, in both modes.

Proof: the new ; cases in tests/unit/send-to-stata/statement-detector.test.ts (6 of 10 fail on main) and tests/unit/send-to-stata/code-to-send.test.ts (new API; covers the prefix for statements, selections, and upward/downward lines). All four gates pass. In StataMP 18 on voyager, I stepped three ; programs statement by statement, as Cmd+Enter with cursor advance would. I ran each send with include in one interactive session, and compared main's sends with this branch's.

StataMP 18: main vs. this branch, stepping three #delimit ; programs

prog1.do:

sysuse auto, clear
#delimit ;
reg price
    mpg /// note
    weight, robust;
di "A"; // trailing note
di "B";

// leading note
summarize
    price;
local a b
/// x
c;
di "[`macval(a)']";
#delimit cr
di "cr " 1+1

prog2.do:

#delimit ;
local total 0;
foreach v in 1 2 3 {;
    local total = `total' + `v';
};
di "total=`total'";
di "one"; di "two"
  "three";
* a star
  comment;
di "after star";

prog3.do:

#delimit ;
mata;
x = 1 +
  2;
x;
end;
di "before";
// c
// d
di "x";

Then a selection of prog2 lines 2-6 and Send Downward Lines from prog1 line 11, both with do. Regression tables and summaries trimmed:

===== prog1 main cursor line 1
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 2
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 3
. reg price
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 4
.     mpg /// note
>     weight, robust;
command mpg is unrecognized
r(199);
rc=199
===== prog1 main cursor line 6
. di "A"; // trailing note
A; invalid name
r(198);
rc=198
===== prog1 main cursor line 7
. di "B";
B; invalid name
r(198);
rc=198
===== prog1 main cursor line 8
. 
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 9
. // leading note
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 10
. summarize
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 11
.     price;
command price is unrecognized
r(199);
rc=199
===== prog1 main cursor line 12
. local a b
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 13
. /// x
rc=0
===== prog1 main cursor line 14
. c;
command c is unrecognized
r(199);
rc=199
===== prog1 main cursor line 15
. di "[`macval(a)']";
[b]; invalid name
r(198);
rc=198
===== prog1 main cursor line 16
. #delimit cr
. . di "rc=" _rc
rc=0
===== prog1 main cursor line 17
. di "cr " 1+1
cr 2
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 1
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 2
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 3
. #delimit ;
. reg price
>     mpg /// note
>     weight, robust;
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 6
. #delimit ;
. di "A";
A
.  // trailing note
rc=0
===== prog1 fix cursor line 7
. #delimit ;
. di "B";
B
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 8
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 9
. #delimit ;
. // leading note
> summarize
>     price;
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 12
. #delimit ;
. local a b
> /// x
> c;
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 15
. #delimit ;
. di "[`macval(a)']";
[b /// x c]
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 16
. #delimit ;
. #delimit cr
. . di "rc=" _rc
rc=0
===== prog1 fix cursor line 17
. di "cr " 1+1
cr 2
. . di "rc=" _rc
rc=0
===== prog2 main cursor line 1
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog2 main cursor line 2
. local total 0;
. . di "rc=" _rc
rc=0
===== prog2 main cursor line 3
. foreach v in 1 2 3 {;
r(198);
rc=198
===== prog2 main cursor line 4
.     local total = `total' + `v';
0; invalid name
r(198);
rc=198
===== prog2 main cursor line 5
. };
} is not a valid command name
r(199);
rc=199
===== prog2 main cursor line 6
. di "total=`total'";
total=0;; invalid name
r(198);
rc=198
===== prog2 main cursor line 7
. di "one"; di "two"
one; invalid name
r(198);
rc=198
===== prog2 main cursor line 8
.   "three";
"three is not a valid command name
r(199);
rc=199
===== prog2 main cursor line 9
. * a star
.   comment;
command comment is unrecognized
r(199);
rc=199
===== prog2 main cursor line 11
. di "after star";
after star; invalid name
r(198);
rc=198
===== prog2 fix cursor line 1
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog2 fix cursor line 2
. #delimit ;
. local total 0;
. . di "rc=" _rc
rc=0
===== prog2 fix cursor line 3
. #delimit ;
. foreach v in 1 2 3 {;
r(612);
rc=612
===== prog2 fix cursor line 4
. #delimit ;
.     local total = `total' + `v';
invalid syntax
r(198);
rc=198
===== prog2 fix cursor line 5
. #delimit ;
. };
} is not a valid command name
r(199);
rc=199
===== prog2 fix cursor line 6
. #delimit ;
. di "total=`total'";
total=0
. . di "rc=" _rc
rc=0
===== prog2 fix cursor line 7
. #delimit ;
. di "one";
.  di "two"
>   "three";
twothree
. . di "rc=" _rc
rc=0
===== prog2 fix cursor line 9
. #delimit ;
. * a star
>   comment;
. . di "rc=" _rc
rc=0
===== prog2 fix cursor line 11
. #delimit ;
. di "after star";
. . di "rc=" _rc
rc=0
===== prog3 main cursor line 1
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog3 main cursor line 2
. mata;
. x = 1 +
command x is unrecognized
r(199);
rc=199
===== prog3 main cursor line 7
. di "before";
before; invalid name
r(198);
rc=198
===== prog3 main cursor line 8
. // c
. . di "rc=" _rc
rc=0
===== prog3 main cursor line 9
. // d
. . di "rc=" _rc
rc=0
===== prog3 main cursor line 10
. di "x";
x; invalid name
r(198);
rc=198
===== prog3 fix cursor line 1
. #delimit ;
. . di "rc=" _rc
rc=0
===== prog3 fix cursor line 2
. #delimit ;
. mata;
>   2;
  3
. . di "rc=" _rc
rc=0
===== prog3 fix cursor line 7
. #delimit ;
. di "before";
. . di "rc=" _rc
rc=0
===== prog3 fix cursor line 8
. #delimit ;
. // c
> // d
> di "x";
/ is not a valid command name
r(199);
rc=199
===== selection main
. local total 0;
. foreach v in 1 2 3 {;
r(198);
rc=198
===== selection fix
. #delimit ;
. local total 0;
. foreach v in 1 2 3 {;
. di "total=`total'";
total=6
. 
rc=0
===== downward main
.     price;
command price is unrecognized
r(199);
rc=199
===== downward fix
. #delimit ;
. // leading note
> summarize
>     price;
. local a b
> /// x
> c;
. di "[`macval(a)']";
[b /// x c]
. #delimit cr
. di "cr " 1+1
cr 2
. 
rc=0
== interactive after sends: 6
. 

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.

Send statement now selects the whole ;-terminated statement in a
#delimit ; region, using the lexer's delimiter state. Code sent from a
; region (statement, selection, downward lines) gets a #delimit ; line
first, since a sent do-file starts under #delimit cr.
@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 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available. Your 50 included PR review attempts over the past 7 days set your current allowance at 4 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: 12869dc6-4574-41d4-baf8-5bd2d5e7584e
Commits

Reviewing files that changed from the base of the PR and between f623a0a and 526057a.

Files selected for processing: 7

  • client/src/send-to-stata/commands.ts
  • client/src/send-to-stata/statement-detector.ts
  • docs/send-to-stata.md
  • tests/integration/send-to-stata-app-temp-file-lifecycle.test.ts
  • tests/integration/send-to-stata-integrated-terminal.test.ts
  • tests/unit/send-to-stata/code-to-send.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 4cba365 into main Nov 5, 2026
14 checks passed
@jbearak
jbearak deleted the send-to-stata-delimit-semicolon branch November 5, 2026 03:38
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