Skip to main content

Module diagnostics_layer

Module diagnostics_layer 

Source
Expand description

DiagnosticsLayer – the editor’s view of every server’s publishDiagnostics events, keyed for multi-server merging and version-gated against stale publishes (Phase 4.1.d.ii).

§Why a separate layer instead of plumbing the bus directly

The renderer and the :diagnostics buffer view both need:

  • Per-URI lookup of the latest set of diagnostics (multi-server-merged when relevant).
  • Per-line severity – what gutter glyph and what underline color to draw on a given line.
  • Workspace-wide enumeration – “show me every URI with any diagnostic, sorted by severity”.

Walking the bus on every render-frame pull is the wrong shape; we’d need to replay the entire history. Instead the layer maintains a HashMap<(Uri, Arc<str>), DiagState> that the bus pump keeps up-to-date, and exposes O(n) lookups against current state.

§Multi-server scenarios

Two servers can attach to the same buffer (rust-analyzer + a clippy linter bridge, c++ + a header-include linter). Each publishes independently. The layer keys by (Uri, server_id) so server A’s clear doesn’t drop server B’s diagnostics on the same file.

diagnostics_for(uri) merges across servers; the consumer sees one combined list.

§Version gating

LSP servers may emit a publishDiagnostics for an older document version after the client has sent a newer didChange. Three rules:

  1. If the incoming event’s version is less than what we already have for (uri, server_id), drop it.
  2. If version matches or is newer, accept.
  3. If version is None, accept (server doesn’t track versions; we can’t gate).

Cross-version checking against the App’s DocSync.version() is the App’s job – the layer only enforces internal monotonicity per (uri, server_id).

§Empty-list = clear

Per LSP spec, an empty diagnostics array means “the server cleared this URI’s diagnostics”. We remove the entry; we don’t store an empty list (which would still appear in iter_uris()).

Structs§

DiagnosticsLayer
Subsystem-wide diagnostics state.
InlineDiagnosticSummary
L4a (lsp-architecture.md §15): a one-line end-of-line summary of the diagnostics on a single line, produced by DiagnosticsLayer::inline_line_summary for the inline cursor-line presentation. The renderer (L4a.3) splices text as trailing virtual text and themes it by severity_rank.
SeverityCounts
Counts of each diagnostic severity in the layer.

Functions§

pump_diagnostics
Drain a DiagnosticEvent broadcast receiver into the layer in a tokio task. Returns when the bus closes (the server is gone). Lagging consumers (Lagged(n)) are tolerated – the next event in the queue still reflects the latest state per URI, which is what callers care about.