Skip to main content

Module document

Module document 

Source
Expand description

M.0 (2026-05-31): Document trait — the handle-layer abstraction over a buffer that the rest of the editor talks to.

Today’s RopeDocumentHandle (a rope-backed actor handle) impls this trait; M.1 lands MultibufferDocumentHandle as a sibling impl composing N source handles. Dispatch / motion / render code paths hold Arc<dyn Document> so they serve both kinds without kind-branching at the buffer boundary.

See docs/dev/architecture/multibuffer-views.md §3.1 for the design and the Path-A/B/C alternatives that were considered and rejected.

§Slot replacement is the only path

There is intentionally no replace(...) method on this trait. Per the M.0 design (§3.1 “Why no replace”), “the active document changes” is expressed by replacing the slot’s Arc<dyn Document> with a freshly spawned handle, not by mutating the existing handle in place. The old handle drops when its last Arc reference goes away; the actor task exits cleanly through its mailbox-close branch. One uniform code path for :edit foo / :edit bar / regular ↔ multibuffer transitions / :b N switches.

§Object safety

Trait is dyn-safe: Arc<dyn Document> is the canonical reference shape. All methods take &self (writes return Pending<T> which round-trips the impl’s internal write path — actor mpsc for RopeDocumentHandle, fan-out for MultibufferDocumentHandle).

Most read methods carry default implementations derived from snapshot() so impls only need to provide snapshot() plus the write methods. MultibufferDocumentHandle may override text() if it can compose more cheaply than snapshot() .text().

Structs§

ActiveDocument
M.0 (2026-05-31): the active-document slot held by Editor.document. Wraps an Arc<dyn Document> so that:
DispatchEnv
N.1.6 (2026-06-10): the owned, thread-safe per-dispatch environment for text objects, carried across the actor channel. Bundles the inputs a text object’s apply may read — the tree-sitter scope_resolver (af/ac, N.1.4) and the comment_syntax (aC/iC, N.1.6) — so the dispatch seam threads ONE value instead of a widening parameter list (the long-term-fit choice over parallel params). The actor borrows these into a lattice_grammar::GrammarEnv at the execute_with_env call. Default is the no-input case.

Traits§

Document
Handle-layer abstraction over a buffer. See module docs.

Type Aliases§

DisplayResolverHandle
VM.3g-2: owned display geometry for gj / gk / g0 / g$.
FoldResolverHandle
VM.3i: the same handle convention for zj / zk’s fold edges. The host builds one from its fold table for a dispatch; the grammar sees a bare &dyn FoldResolver.
IndentResolverHandle
IN.7: the same handle convention for the = operator’s per-line indent source. Owned + Send + Sync so it can cross the actor channel; the grammar side sees a bare &dyn IndentResolver.
MarkResolverHandle
VM.3e: owned mark table for 'x / `x, like FoldResolverHandle.
ScopeResolverHandle
N.1.4b (2026-06-10): a sharable, thread-safe scope resolver handle threaded through grammar dispatch. The host wraps the active document’s Arc<SyntaxSnapshot> (which impls lattice_grammar::ScopeResolver) in this alias, bundles it into a DispatchEnv, and passes it to Document::dispatch_with_env; the actor hands it to execute_with_env so tree-sitter text objects (af/ac/aa/al) resolve against the live tree. Send + Sync because the actor message crosses the dispatch channel onto the document-actor thread. The bare ScopeResolver trait lives in lattice-grammar (tree-sitter-agnostic); this threading-layer alias adds the Arc + Send + Sync shape per the handle convention (cf. CommandRegistryHandle).
ViewportResolverHandle
VM.3f: owned window lines for H / M / L, like FoldResolverHandle.