Expand description
MessagesLayer: a tracing::Layer that fans every event
into the App’s MessagesRing + publishes a typed
MessagePushed on the editor event bus.
Per docs/dev/architecture/design.md §5.10.6, *messages* is
the editor’s audit log: every record App::set_message
produces, plus every tracing::* event from the editor +
plugins, flows through this single subscriber into one
buffer. The subscriber:
- Captures every event, irrespective of where it
originated (App code,
lattice-lsp, future plugin host). - Translates
tracing::Leveltolattice_grammar::EchoLevelfor parity with the legacyset_messagerecords (same wire enum either way). - Pushes to
MessagesRingfor backlog seeding when the user opens*messages*mid-session. - Publishes
MessagePushedso per-tick drains in the App (drain_message_events) can append to the buffer.
§Install once at App boot
install_messages_subscriber calls
tracing_subscriber::registry().with(MessagesLayer { ... }).set_global_default(). The global default can only be
installed once per process — multi-App test setups must use
the no-install path (a MessagesLayer can still be
constructed and exercised directly for unit tests; only the
global install is gated).
§Hot-path cost
When no subscriber is installed, tracing::info! is a
const-time atomic load → ~10ns per call (the tracing crate’s
commitment). When the layer is installed:
record_debug visitor allocs ~one string + a Mutex::lock
on MessagesRing + bus publish. Total ~hundreds of ns per
event — acceptable because LSP / mode events fire at human
cadence, not keystroke cadence (per §8.2 Background-class).
Structs§
- Messages
Layer tracing::Layerthat bridges every event into theMessagesRing+ bus. Cheap to construct; cloning the layer shares the underlying ring + bus handles viaArc.
Enums§
- Messages
Filter Reload Error - Why a
reload_messages_filtercall failed.
Functions§
- boot_
log_ level editor_bootreads the boot-time log level when callinginstall_messages_subscriber. ReturnsNonewhen the CLI didn’t set one (typical for tests + library callers); boot falls back to"info".- boot_
stderr_ enabled editor_bootreads the boot-time stderr-enabled flag. ReturnsNonewhen the CLI didn’t set one (test paths and library callers); editor_boot falls back tofalse(safe — never accidentally corrupt a TUI screen).- install_
messages_ subscriber - Install
MessagesLayeras the global tracing subscriber, gated by anEnvFilterwhose initial directive isinitial_filter. The filter is reloadable – live edits viareload_messages_filterswap the directive without re-installing the subscriber. - reload_
messages_ filter - Live-swap the messages-layer filter directive. Returns
Errwhen the directive fails to parse, when the global subscriber wasn’t installed (test paths), or when the reload handle has been dropped. The App’s option-change cascade calls this on:set messages.filter=<spec>. - set_
boot_ log_ level - CLI sets the boot-time log level before constructing the
editor. Idempotent — second call no-ops. The first set
wins (matching
tokio::main->App::newordering). - set_
boot_ stderr_ enabled - CLI sets the boot-time stderr-enabled flag before constructing the editor. Idempotent — second call no-ops.