Skip to content

Send whole lines again under #delimit ; so Send Statement never skips or repeats code, and send input from a data line as its whole block - #424

Merged
jbearak merged 3 commits into
mainfrom
t3/fix-send-statement-boundaries
Nov 19, 2026
Merged

jbearak merged 3 commits into
mainfrom
t3/fix-send-statement-boundaries

Conversation

@jbearak

@jbearak jbearak commented Nov 19, 2026

Copy link
Copy Markdown
Owner

#420 made Send Statement under #delimit ; cut lines at statement boundaries, character by character. That broke cases that worked before it. Stepping through a file with repeated Send Statement could skip an if/else chain or run a command twice. It could also cut a comment in half or send a lone input data row, and a large block took seconds to send.

Design: whole lines again, with one cut. Making character-level cutting correct for every shape (one-line if/else, closers, comments ending mid-line, input data, cr regions switching to #delimit ;) kept needing special cases. So sends take whole lines again, as at 6d98b9b before #420. The one exception is the case #420 was written for, and only where it's safe: a line that ends a statement whose code began on an earlier line and then holds only complete statements of its own (display / 1; clear;). A send from above ends at that statement's ; and leaves the cursor on the line. Send Statement there sends the rest. If the line is joined to the next one, has a block header or closer after the cut, holds a #delimit, or opens with the end of a comment, it is sent whole. One function decides the cut for both sends, so the two halves always add up to the whole line. Send Upward Lines ends at the same cut, and Send Downward Lines starts after it unless that falls inside a block's body. #420's per-version reading cache and its release-workflow change are untouched.

Fixed (review items; text sent, #delimit ; line omitted):

Item origin/main this PR
1: di 1; if 1 di 2; / else di 3; di 4;, stepping di 1; → di 4; both lines, once
2: replace x = x + 1; /* note / continued */, stepping replace…; /* note → replace…; /* note\ncontinued */ → di 2; replace…; /* note\ncontinued */ → di 2;
2: Send Upward Lines from line 1 replace…; /* note (comment cut) both lines
11: input x; / 1; / 2; / end;, cursor on 2; 1;\n2; (cr mode: 1\n2) input x; … end; in both modes
12: quietly {; around 12,000 if blocks, cached send 2,313 ms 23.9 ms
4: * comment / ends; erase important.dta;, stepping * comment\nends; erase important.dta; * comment\nends; → erase important.dta;

Also fixed, found by the new property test. These bugs are in the whole-line code and were already there at 6d98b9b:

  • A closer line that continues onto the next line (}; di /// / m1;) sent half of di. Widening to a block now follows joined lines in both directions, and still looks at each line once.
  • A line holding one block's closer and another's if header (di 1; }; if 1 di 2; / else di 3;) sent the if without its else. Lines now record the extent of every block on them, not just one.
  • // note / di 1; di 2; with the cursor on the second line sent only di 2; (main too).

Not fixed (item 4; the design keeps these whole-line, as before #420):

  • erase sensitive.dta;foreach x in a {; … };: Send Statement from the closer still sends the erase.
  • A cr program define p with a #delimit ; body closed by end; clear;: sending the header still sends clear;.

#420 behavior deliberately reverted to whole lines: on }; clear;, Send Statement sends the block with clear;. On clear; display / 1;, either line sends both statements. Code before a header on its line, and a cursor on a middle line, send from the statement's first line.

Proof: the new regression and step-through property tests fail on origin/main and pass here. The property test steps through generated #delimit ;, cr, and mixed documents. It checks that the sends, each lexed on its own, add up to the document's tokens: every statement once and in order, with no comment or string cut. The cut path is exercised: about 3.5% of generated sends are cuts. On 466fdc4, check:line-endings, typecheck, bun test ./tests (10,151 pass, 0 fail), lint, test:ci, and package all pass, run separately.

Created with Claude Opus 5.5 in Claude Code.

jbearak and others added 2 commits November 19, 2026 10:41
… or repeats code, and send input from a data line as its whole block

#420 cut #delimit ; lines at statement boundaries by character. That
skipped a one-line if/else chain sharing lines with other statements,
sent a command twice when a block comment after its ; ended on the next
line (and cut the comment in Send Upward Lines), sent a lone input data
row, and took seconds on a large block because widening searched every
statement for each block edge.

Sends take whole lines again, as before #420, with one cut: a line that
ends a statement begun above it and then holds whole statements of its
own (display / 1; clear;). A send from above ends at that statement's ;
and leaves the cursor on the line; Send Statement there sends the rest.
A * comment whose ; is on a later line counts as such a statement.
Anything else, such as a closer, a header, or a comment ending on the
line, keeps the line whole.

Fixed in the whole-line code too: a block's closer line that continues
onto the next line (}; di ///) now takes that line, and a line holding
one block's closer and another's header takes both blocks. Every line of
input through its end now sends the whole block.

A property test steps through generated #delimit ; and cr documents
and checks that the sends, lexed one by one, add up to the document's
tokens: each statement once, in order, no comment or string cut.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…starts above it

With // note on one line and di 1; di 2; on the next, Send Statement on
the second line sent only di 2;, since the statement di 1; counted as
begun at its comment. A cut now needs the statement's code to start on
an earlier line. The step-through property also generates a comment
line before a statement and a cr program whose body switches to
#delimit ;.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@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 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 87 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: 56ffb2cb-dd60-40ea-b10b-70939acd9cbe
Commits

Reviewing files that changed from the base of the PR and between 93d8ec8 and 9478744.

Files selected for processing: 5

  • client/src/send-to-stata/statement-detector.ts
  • docs/send-to-stata.md
  • tests/property/send-statement-step-through.prop.test.ts
  • tests/unit/send-to-stata/semicolon-shared-lines.test.ts
  • tests/unit/send-to-stata/send-statement-regressions.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

jbearak added a commit that referenced this pull request Nov 19, 2026
…at ignored holds, and di/pr as random command names (#427)

* Make the app temp-file test's mock honor holds, so test order can't delete a held file

Bun keeps a module mock for later test files. This file's mock of
temp-file.ts had no hold_temp_file/release_temp_file and deleted
unconditionally, so when it ran before temp-file.test.ts (or without
the integrated-terminal test loading first) the held-file test failed
with ENOENT, as it did in CI on #424.

* Keep di, pr and other specially parsed names out of the varlist property test's command names

A random two-letter name is sometimes di (display's arguments are not
a varlist) or pr (a program definition), which failed CI on this PR
with counterexamples ["di","_",1] and ["_","pr","a",1]. The
parser reads both the same way at 6d98b9b, so the test was already
flaky.
@jbearak
jbearak merged commit d058276 into main Nov 19, 2026
14 checks passed
@jbearak
jbearak deleted the t3/fix-send-statement-boundaries branch November 19, 2026 16:17
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