Skip to main content

0016: One transaction engine for user, language-server and AI edits

  • Status: Proposed (implemented in Phase 2, task 009)
  • Date: 2026-12-05

Context​

Replace-in-files, language-server rename and code actions, and AI edits all change several places in several files at once. Each could apply its edits its own way. That would give three sets of path checks, three conflict rules, and three answers to "what does undo do". A bug in any one of them could write outside the folder or overwrite unsaved work.

Decision​

  • Every multi-place change is an EditProposal: a title, its source (user, language server or AI), an explanation, evidence and a list of FileChanges. Each change targets an open document at a known revision, a file on disk at a known fingerprint (or "not open, whatever is there"), or a new file. Each edit has a range (chars, UTF-16 or line plus columns), replacement text, and optionally the text it expects to replace.

  • Preflight checks the whole proposal before anything changes:

    • paths must be absolute, inside the open folder after resolving the parent, with a plain final name and no symbolic link;
    • targets must be regular files;
    • ranges must be valid and must not overlap;
    • document revisions and disk fingerprints must still match;
    • new files must not exist.

    One failure refuses the whole proposal and lists every conflict.

  • Apply works in memory only. Edits run in descending order, through the existing history, as one undo group per document. Files that were not open are loaded into buffers and new files become unsaved buffers. Nothing is saved automatically: the user reviews and saves, and the save goes through the normal safe-save path, file by file.

  • Partial acceptance (individual files or edits) re-runs preflight on the accepted subset. A stale proposal is rebased only when every edit carries expected text that is still found at the same place; otherwise it is refused.

  • A bounded journal (32 entries) records each applied proposal with the revision it produced per document. Undo Last Multi-File Change reverts all of its documents only if none was edited since. Otherwise it refuses and leaves everything as it is. Documents it opened and left clean are closed again.

  • proposal_from_lsp converts a WorkspaceEdit into a proposal: versioned edits must match the version the server saw, and file create, rename and delete operations are refused. AI edits (tasks 018 and 019) will build proposals the same way.

Alternatives considered​

  • Write proposals straight to disk: simpler for files that are not open, but loses undo and review, and makes a half-written multi-file change visible to other tools. Rejected.
  • Filesystem-wide atomic commit: no portable way to do it; staging plus per-file safe save is the honest guarantee.
  • Silent rebase of stale edits by offset shifting: can land edits in the wrong place after unrelated changes. Rejected in favour of expected-text checks.

Consequences​

  • One set of scope and conflict rules for every source of edits, tested once.
  • Multi-file changes are atomic in memory, not on disk: saving several files can still partly fail, and the save report lists which files failed.
  • A document edited after a proposal was applied blocks the journal undo for that proposal; per-document undo still works.

Validation​

crates/ide-core/tests/transactions.rs covers overlap, stale revision, disk-version and new-file conflicts, path escapes and symbolic links, partial acceptance with rebase, one-step undo, journal refusal after a later edit, and LSP conversion. The desktop review dialog is driven through the real UI in apps/desktop/src/ui_tests.rs.