Skip to main content

Module messages_subscriber

Module messages_subscriber 

Source
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::Level to lattice_grammar::EchoLevel for parity with the legacy set_message records (same wire enum either way).
  • Pushes to MessagesRing for backlog seeding when the user opens *messages* mid-session.
  • Publishes MessagePushed so 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§

MessagesLayer
tracing::Layer that bridges every event into the MessagesRing + bus. Cheap to construct; cloning the layer shares the underlying ring + bus handles via Arc.

Enums§

MessagesFilterReloadError
Why a reload_messages_filter call failed.

Functions§

boot_log_level
editor_boot reads the boot-time log level when calling install_messages_subscriber. Returns None when the CLI didn’t set one (typical for tests + library callers); boot falls back to "info".
boot_stderr_enabled
editor_boot reads the boot-time stderr-enabled flag. Returns None when the CLI didn’t set one (test paths and library callers); editor_boot falls back to false (safe — never accidentally corrupt a TUI screen).
install_messages_subscriber
Install MessagesLayer as the global tracing subscriber, gated by an EnvFilter whose initial directive is initial_filter. The filter is reloadable – live edits via reload_messages_filter swap the directive without re-installing the subscriber.
reload_messages_filter
Live-swap the messages-layer filter directive. Returns Err when 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::new ordering).
set_boot_stderr_enabled
CLI sets the boot-time stderr-enabled flag before constructing the editor. Idempotent — second call no-ops.