Skip to main content

0017: Semantic editor features over checked, negotiated LSP requests

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

Context​

Completion, hover, signature help, references, formatting, rename and quick fixes all come from language servers. Servers differ in what they support, answer late or out of order, and some answers change text in several files. Each feature could talk to the server and edit text its own way. That would mean guessing at unsupported features, applying answers computed for older text, and letting a server change files the user never saw.

Decision​

  • Negotiate, never pretend. SemanticOp::supported_by reads the server's capabilities; an explicit false counts as unsupported. LanguageServiceManager::request refuses an operation the server did not advertise before anything is sent, and the UI keeps the command but reports that the server does not offer it. Axiom advertises only what it handles: UTF-16 positions, no snippet support (a documented subset is still expanded if a server sends one), insert/replace completion edits, resolve of documentation, detail and additionalTextEdits, versioned documentChanges, no resource operations and no workspace/applyEdit.
  • One typed request path. Every request is a SemanticRequest with a ticket (document, revision, caret, generation). A newer request of the same kind cancels the older one ($/cancelRequest). Answers are decoded on the reader thread into SemanticResponse with size limits; a malformed answer becomes an error naming the method, not a partial guess.
  • Stale answers are dropped or refused. Caret-bound answers (completion, hover, signature help) are dropped when the caret moves; others when the document changes. Completion edits are re-checked against the current text: a range that ended at the request caret is extended over what was typed since; anything else that changed, any overlap or any position outside the text refuses the item with a notice.
  • Edits go through the transaction engine (ADR 0016). Completion and formatting apply directly as one undo step, because the user asked for exactly that edit in the current file. Rename and code actions produce an EditProposal that opens the review dialog; nothing changes until the user applies it, and nothing is saved.
  • Server commands are never run. A code action that only carries a command is listed as unavailable. Axiom answers workspace/applyEdit with MethodNotFound, so a server cannot change files on its own.
  • Diagnostics for closed files are kept in a bounded store (1000 files × 1000 diagnostics per server) keyed by path, for the problems list. Open documents always show their live, version-checked diagnostics.

Alternatives considered​

  • Execute server commands (workspace/executeCommand) and accept workspace/applyEdit: needed by some refactorings, but it lets a server change files without review. Deferred until there is a review path for server-initiated edits.
  • Advertise full snippet support: servers would send snippets with nested placeholders and transformations that Axiom cannot edit interactively yet. Instead it advertises plain text and expands a safe subset if a snippet arrives anyway.
  • Send every request and show errors: simpler, but users would see failures for features the server never claimed, and some servers answer unknown methods slowly. Rejected.

Consequences​

  • The capability matrix in LSP integration is the single answer to "why is this feature missing for language X".
  • Refactorings that depend on server commands (for example rust-analyzer's "run test" lenses or some quick fixes) are not available.
  • Completion is insert mode only; replace mode of insert/replace edits is not offered.

Validation​

crates/ide-languages/tests/lsp_semantic.rs covers negotiation, decoding of every request kind with UTF-16 positions, supersede and cancellation, and malformed answers. crates/ide-core/tests/semantics.rs covers completion while typing with one undo, resolve-only edits, snippets, refused stale and overlapping edits, hover, signature help, references, formatting, rename and code actions through review, closed-file problems and unsupported servers. apps/desktop/src/ui_tests.rs drives the popups, key routing, problems panel and quick-fix review through the real UI with the fake server.