Expand description
BufferStore: host primitive for mode-owned buffer lifecycles.
Modes that synthesize their own buffers (LSP log family,
*messages*, future *scratch*, plugin-installed log streams)
need a thread-safe way to:
- Find a buffer by its synthetic name (idempotency check).
- Create a new Document with a given major mode active on it.
- Look up a Document’s handle so the mode can append to it from a background tokio task.
Why a trait + handle pair: the concrete buffer registry lives
in the renderer crate (lattice-ui-tui::buffer_registry), but
mode crates (lattice-lsp, eventually plugin modes) shouldn’t
depend on the renderer. The trait carries the host-side
contract; the renderer registers an Arc<dyn BufferStore> into
crate::ServiceRegistry at App boot; modes pull
Arc<BufferStoreHandle> via ctx.service::<BufferStoreHandle>()
and call through it.
§Threading model
Operations on the trait are &self; the implementation is
responsible for whatever synchronisation it needs (the
lattice-ui-tui impl wraps the relevant App state in
Arc<Mutex<...>>). Modes can call from any thread — the App
thread inside on_activate, a tokio task draining an event
subscription, etc.
§Read / write surface
BufferStore::find_by_name— read-only registry probe.BufferStore::handle_for— clone of the actor handle so a mode can write to the buffer from outside the App’s borrow.BufferStore::insert_document_buffer— generic Document-shaped insertion (multibuffer kinds).
Buffer creation (find-or-create + activate a major) is NOT on
this trait. Activating a mode mutates the mode registry /
active-modes / options cache, which needs &mut Editor;
BufferStore is &self (thread-safe). The reliable, mode-owned
creation seam is crate::ModeActivator::ensure_named_document
(&mut-backed) — a mode / provider provisions its own buffer there.
Mode authors call these from their lifecycle hooks. The
mode-ownership contract: a mode that creates a synthetic
buffer is the only thing that writes to it (subsystem writes
via the handle; user writes are gated by ReadOnly).
Structs§
- Buffer
Store Handle - Concrete service-registry-friendly wrapper around
Arc<dyn BufferStore>. Modes register interest by pullingArc<BufferStoreHandle>fromcrate::ServiceRegistry::get::<BufferStoreHandle>().
Traits§
- Buffer
Store - Host-implemented trait. The renderer crate provides an impl that wraps the App’s buffer registry + mode-activation state.