Expand description
Unified buffer registry (DESIGN.md §5.9).
Every concrete buffer the App can route input through – a code
Document today, a FileTreeBuffer tomorrow – lives in
BufferRegistry keyed by BufferId. A single registry
gives :bn / :bp / :ls / :bd a consistent surface across
buffer kinds; multiple file trees coexist with multiple
documents under the same shape.
§Threading model (B’.1b)
BufferRegistry uses interior mutability via
Arc<Mutex<BufferRegistryInner>>. Every method takes &self
and locks briefly. The registry is Clone (cheap atomic
bump) so the App’s BufferStore service impl can hold the
same state as the App’s buffers field — modes call into
the shared store from any thread; the App accesses the same
data through its direct field.
Methods that previously returned Option<&BufferEntry> (and
kind-specific equivalents like document(id)) are replaced
with two flavours:
- Owned-return convenience methods for common patterns
(
document_handle,name_of,kind_of,flags_of,document_dirty,document_path,entry_summary). - Callback methods (
with_entry,with_document, etc.) for one-off access. The callback runs while the lock is held; callers MUST NOT re-enter the registry from inside (it would deadlock on the sameMutex).
Help buffers stay overlay-rendered for v1 (transient popup), so they’re not in the registry yet – moving them in is a follow-up that doesn’t require structural change.
Hot-path access: the active document’s actor handle, syntax
state, and last-parsed-version live on [crate::app::App]
directly so motion / dispatch code stays unchanged. Switching
the active document snapshots those fields back into the
matching registry entry and loads from the destination’s.
Structs§
- Buffer
Entry - One slot in the registry. The kind-specific data lives in
BufferData; flags + id + name apply uniformly. - Buffer
Registry - The App’s buffer registry. Methods take
&selfand lock internally; the registry isCloneso the App’sBufferStoreservice impl can hold a clone for cross-thread access. - Document
Entry - Per-document registry payload. Each entry carries the actor
handle plus per-document tree-sitter
Syntaxstate, fold list, and any other “lives with this buffer until it closes” state.
Enums§
- Buffer
Data - Listing
Kind - DL.4/DL.5: which listing kind a new listing Document is filed
under. Both are
DocumentEntry-backed; only the discriminator differs, which is exactly the PU.1a shape.