Skip to main content

Module buffer_store

Module buffer_store 

Source
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

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§

BufferStoreHandle
Concrete service-registry-friendly wrapper around Arc<dyn BufferStore>. Modes register interest by pulling Arc<BufferStoreHandle> from crate::ServiceRegistry::get::<BufferStoreHandle>().

Traits§

BufferStore
Host-implemented trait. The renderer crate provides an impl that wraps the App’s buffer registry + mode-activation state.