Skip to main content

Module handle

Module handle 

Source
Expand description

RopeDocumentHandle – the public API for talking to a document actor. Cheap to clone (an mpsc::Sender + an Arc<PublishedSnapshot>); pass to any thread, hold for any lifetime, give to plugins.

§Operations

Mutating methods (apply_edit, undo, redo, save, save_as, set_selections) all return Pending<T>. Per DESIGN.md §5.2.1 the dispatcher MUST NOT block the caller – so these never await on the actor; they enqueue and return.

M.0 (2026-05-31): there is no replace(...) method. “The active document changes” is expressed as slot replacement — assign a fresh handle to the Editor.document slot; the old handle drops and its actor task exits cleanly when no other caller holds it. See docs/dev/architecture/multibuffer-views .md §3.1 “Why no replace.”

Read methods (RopeDocumentHandle::snapshot and the convenience pass-throughs text, path, dirty, version, text_version, selections) are wait-free and return immediately from the published snapshot. They never round-trip the actor.

§Mailbox semantics

The mailbox is tokio::sync::mpsc::unbounded_channel (audit slice 6 / H3). Mutating methods send synchronously; the only failure mode is RuntimeError::ActorGone, surfaced when the actor task has terminated. The previous bounded-channel + RuntimeError::Busy design dropped edits silently when the App’s apply_edit_blocking discarded the Busy variant under bursts; the unbounded channel makes this class of bug structurally impossible. Queue depth bounds itself by edit rate × actor stall (typing is human-paced; a few KB at most).

Structs§

RopeDocumentHandle
Cheap-clone handle to one document actor. All callers (App, renderer, future LSP clients, plugins) talk to the actor through a RopeDocumentHandle – there is no other way to reach the document’s writable state.

Functions§

spawn_document
Spawn a fresh document actor on the shared runtime and return the handle. Calling this is the only way to obtain a RopeDocumentHandle. Document moves into the actor; once spawned the document is reachable only through the handle.