Skip to main content

Module apply_edit

Module apply_edit 

Source
Expand description

Server-initiated workspace/applyEdit plumbing (Phase 4.3; BC.8d reshape).

When a language server sends workspace/applyEdit (most commonly during workspace/executeCommand callbacks for code actions) the client must:

  1. Apply the supplied [lsp_types::WorkspaceEdit] to the affected buffers.
  2. Reply with ApplyWorkspaceEditResponse { applied, failure_reason, failed_change } so the server knows whether to roll back its own state.

Step 1 needs the editor’s mutable buffer state (&mut Editor); step 2 must come back on the tokio actor’s task. The bridge is a channel: the actor receives the request, packages it into InboundApplyEdit (with a oneshot for the response), and sends it through ApplyEditBus. The host drains the receiver each tick, applies the edit, and writes the ApplyEditOutcome back through the oneshot. The actor’s spawned response-task reads the oneshot, builds the LSP Response, and ferries it to the wire.

BC.8d (2026-06-24): reshaped onto the generic inbound primitive. ApplyEditBus is now a type alias for the generic InboundBus built via make_inbound_raw: its send wakes the editor, so a server-initiated edit is applied off-keystroke (was: no wake — it only landed on the next keypress). Unlike the configuration / show-document buses, this is the host-drained variant: the apply (Editor::apply_inbound_workspace_edit) is irreducibly &mut Editor and carries lsp_types, which cannot cross the Effect boundary into a mode-owned handler — so the host keeps the receiver (Editor::pending_apply_edit_rx) and drains it in run_tick_pending, while the bus contributes only the structural wake. This keeps the irreducible apply as documented host residue (the diff-lifecycle / multibuffer Effect-arm class) without introducing an internal-pump Effect. The real-outcome reply (applied reflects what actually landed) is preserved.

Structs§

ApplyEditOutcome
Result the host reports back to the actor’s response task. Mirrors ApplyWorkspaceEditResponse minus the failed_change index which the host doesn’t track today (every per-file edit is a separate batch; partial-apply with a failure echoes a warning but doesn’t roll back). Future atomic-rollback work fills failed_change.
InboundApplyEdit
One server-initiated workspace/applyEdit request, ferried from the LSP actor’s task to the host’s drain. Carries the untyped LSP WorkspaceEdit (the host reuses its existing flatten + apply path) plus a oneshot the host fills with the outcome.

Type Aliases§

ApplyEditBus
The bus the supervisor fans out to each actor – the generic inbound primitive specialised to the apply-edit payload, built host-drained via make_inbound_raw. send wakes the editor; the host owns the matching receiver and drains it. (Was the bespoke ApplyEditBus struct before BC.8d.)