Expand description
LSP logging facade – the producer side of the
*lsp* / *lsp:<server>* / *lsp:<server>:trace*
buffer views (Phase 4.1.f).
§Inspiration
emacs’s lsp-mode puts subsystem events in *lsp-log* and
per-server stderr in *<server> stderr*. eglot’s
*EGLOT (project/lang) events* captures the JSON-RPC trace
when toggled. lattice combines both ideas under
everything-is-a-buffer (§5.9):
- Subsystem buffer (
*lsp*) – supervisor events (spawn / handshake / crash / restart) plus cross-server messages. - Per-server buffer (
*lsp:<server-id>*) – stderr +window/logMessage+window/showMessage+ lifecycle for one server. - Per-server trace (
*lsp:<server-id>:trace*) – every inbound / outbound JSON-RPC message. Off by default; toggle with:lsp-trace <server>.
§Producer / consumer split
This module is the producer: actors and the supervisor
emit LogRecords through LspLogger::log. Records land
in bounded LogRings held inside the logger.
The consumer – buffer-backed log views in
lattice-ui-tui – snapshots a ring on demand via
LspLogger::snapshot_global /
[LspLogger::snapshot_server] and renders the records.
Auto-scroll-to-tail and live tail-follow are buffer-side
concerns; the producer just appends.
§Tracing crate fan-out
Every LspLogger::log call also emits a tracing::* event
at the matching level so users who prefer
RUST_LOG=lattice_lsp=debug ./lattice still see
everything. The two paths are independent: the in-memory
rings survive even when no tracing subscriber is
installed, and tracing users see the same events whether
or not the buffer views are open.
Structs§
- Instance
Key - Composite key for the per-instance log ring – the
(server_id, workspace_root)pair that the supervisor uses to key actors. Tworust-analyzerprocesses against different workspaces stay distinct in the logger and in the buffer name. Cheap to clone (twoArcs). - LogRecord
- One log entry. Cheap to clone (
Arc<str>for server id,Arc<Path>for workspace; the message is a plainString). - LogRing
- Bounded ring of log records. Append-only; oldest is evicted when capacity is reached.
- LspLogger
- Producer-side log facade. One per LSP subsystem; each actor
gets a clone (cheap – internal state is
Arc<Mutex<...>>).
Enums§
- LogLevel
- Severity levels. Ordered low-to-high so the derived
PartialOrdmatches “Error > Warn > … > Trace”. Per-server min level filters records BELOW it (i.e.level < mindrops;level >= minkeeps). - LogSource
- Where a log record originated.
Functions§
- format_
log_ event_ line - Format one log record line for append to a synthetic LSP log
buffer (B’.3: hoisted out of
lattice_ui_tui::app::lsp_log_buffersso log modes in this crate can reuse it from a tokio task). Shape:HH:MM:SS.mmm [<server>] <level> <source>: <message>. Trailing newline is the caller’s responsibility (the drain batches many records into one buffer-append). - level_
tag - Compact severity tag for
LspLogPushed. MirrorsLogSource::tag’s shape for the level discriminator.
Type Aliases§
- LogEvent
Publisher - Closure invoked on every successful append. Wired by the App
(or test harness) to publish
LspLogPushedonto the runtime event bus viaEventBus::publish_typed, which lets log buffers refresh live as records arrive. Optional:LspLogger::with_defaults()starts with no publisher;set_event_publisherinstalls one.