Skip to content

Portable targets: document session + edit API (S1, full-reparse fallback)#61

Merged
johnsoncodehk merged 1 commit into
masterfrom
portable-edit-s1
Jul 11, 2026
Merged

Portable targets: document session + edit API (S1, full-reparse fallback)#61
johnsoncodehk merged 1 commit into
masterfrom
portable-edit-s1

Conversation

@johnsoncodehk

Copy link
Copy Markdown
Owner

Summary

First slice of #57: all three portable targets (TS/Go/Rust) gain a document session + edit API. The API shape is now fixed; later slices swap the internals for true incremental reuse without touching the interface.

  • TS: createDoc(src){ text(), root(), edit(edits) } with Edit = { start, end, text }
  • Go: Doc struct + NewDoc / Text / Root / Edit
  • Rust: Doc holds the owned String; edit splices text, parse() borrows on demand (sidesteps the Parser<'a> self-reference)
  • Edit semantics (uniform): each (start, end, text) replaces [start, end); edits apply sequentially; offsets in each target's native CST offset units
  • Internals delegate to the existing tokenize/parse (full re-parse — no incremental reuse in this slice, by design); existing lexer/parser function bodies are append-only unchanged
  • Runner gains an edit-session mode ({init, batches} JSON on stdin, same CST JSON output), so the gate can adjudicate sessions

Validation

  • test/portable-targets.ts: 8 scripted edit scenarios (insert/delete/replace/multi-batch, including same-batch offset chaining) × 3 targets — all edit-session ≡ fresh parse of final text byte-identical + oracle parity; all existing accept/reject counts unchanged
  • node test/check.ts emit-parity — 5/5
  • npx tsc --noEmit — clean
  • Planner adversarial probe: 4 extra scenarios outside the gate (reject-final, empty-final, append-at-end, reject-intermediate-state) × 3 targets — 12/12 parity

Part of #57 (S1 of the slicing plan; S2+ — windowed relex, arena persistence, adoption — tracked separately).

Introduce document session + edit API for ts/go/rust portable targets
with text splice and full re-tokenize/parse, plus edit-session runner
protocol and gate coverage for calc and javascript.

Co-authored-by: Cursor <cursoragent@cursor.com>
@johnsoncodehk johnsoncodehk merged commit ffce09c into master Jul 11, 2026
3 checks passed
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