Skip to main content

Module cache

Module cache 

Source
Expand description

Per-buffer LSP response caches + outcome enums.

Phase 5.2: extracted from lattice-ui-tui::app to their proper home in lattice-lsp. Every type here is renderer-agnostic pure data describing the result of an LSP request – the shape the App’s per-tick drain expects after the spawned task delivers its response.

Cache types are keyed on (BufferId, document_version) so the pump can invalidate-by-version when the buffer mutates. Outcome enums carry the same key plus the actual payload (or a sentinel variant for Empty / NoProvider / etc.) so the drain can route to the appropriate echo / apply path.

lattice-ui-tui::app re-exports every type from this module so existing crate::app::HoverOutcome etc. references in the host crate’s source continue to resolve unchanged.

Structs§

CodeActionRow
One row of a code-action picker. Carries the action title, kind glyph, and the original CodeAction payload (or its raw Command-only form). Action items survive on the App across the request → picker accept gap so the resolve / apply path can read them by index.
CompletionItemRow
One row of an LSP completion picker. Carries the item label, kind glyph, optional detail blurb, and the insert text. replace_range is the byte range in the active line to splice the insert text over.
CompletionResolveOutcome
Drain payload for completionItem/resolve (Phase 4.2.g.3). CSM.8b.5: meta_index is now the index of the fired candidate within state.raw’s LSP-row sequence; the drain decodes that row’s payload, applies the resolved fields, re-encodes in place. Multiple resolves in flight (selection change → cancel prior → fire new) cancel via the supplied token.
DecodedSemanticToken
4.4.h: one decoded LSP semantic token, expanded from the server’s relative-position varint encoding into absolute positions. token_type is the canonical name from the server’s legend (e.g. "keyword", "function") so the renderer can pick a style without looking up the index. length is in utf-16 code units per the LSP spec.
DocumentHighlightCache
4.4.e: cached textDocument/documentHighlight result anchored at a specific buffer + cursor position. The renderer reads highlights to paint a soft overlay; the pump compares cursor to the live cursor to decide whether to invalidate and re-request.
LspCodeLensCache
4.5.d: per-buffer cache of textDocument/codeLens results. Filled by the pump on doc-version change or after workspace/codeLens/refresh evicts the entry. The :lsp-code-lens picker reads the cache; accept routes the chosen lens’s command through workspace/executeCommand.
LspDocumentColorCache
4.5.e: per-buffer cache of color literals + their resolved values. Filled by the per-tick pump on document-version change; consumed by :lsp-color-presentation. Renderer swatch overlay queued – today the cache only feeds the picker.
LspDocumentLinksCache
4.5.c: per-buffer cache of textDocument/documentLink responses. Filled by the pump on document-version change; gx walks the entries looking for the first link whose range covers the cursor and follows it. Cache invalidates when the version changes.
LspFoldsCache
4.4.f: cached textDocument/foldingRange response for one buffer. document_version is the buffer’s [lattice_core::Document] version at the time the request was issued; the pump compares it against the live version to decide whether to refresh.
LspInlayHintCache
4.4.g: cached textDocument/inlayHint response for one buffer. Keyed on (BufferId, document_version); pump invalidates when the version changes. hints are sorted by position so the renderer can stop scanning once it walks past the current line.
LspPullDiagnosticsCache
4.4.j: cached textDocument/diagnostic state per buffer. result_id is what the server issued on the previous response; threading it back in previous_result_id lets the server answer Unchanged when nothing moved.
LspSelectionChain
4.4.e: cached textDocument/selectionRange chain anchored at a specific buffer + cursor position. Flat Vec<Range> (innermost first) instead of the LSP linked-list shape so the operator can index into it in O(1). Captured once on the first :lsp-expand-region after a fresh cursor; reused across subsequent expand/shrink steps until the cursor moves outside ranges[0] (the innermost) or the buffer changes.
LspSemanticTokensCache
4.4.h: cached decoded textDocument/semanticTokens/full response for one buffer. Same shape as the other LSP per-buffer caches: keyed on (BufferId, document_version), invalidated by the pump when the version changes.
SymbolRow
One row of a document-symbol / workspace-symbol picker. Carries the symbol’s name, kind, depth (for in-document hierarchy indent), and the location to jump to. Built host-side from the LSP DocumentSymbolResponse / Vec<SymbolInformation> so the picker doesn’t depend on lsp-types.

Enums§

CodeActionOutcome
Outcome of a :code-actions request. Drained per frame.
CodeLensOutcome
4.5.d: outcome of an in-flight textDocument/codeLens request. Carries the server id so the eviction-on-refresh path can match by server.
CompletionOutcome
Outcome of a textDocument/completion request.
DocumentColorOutcome
4.5.e: outcome of an in-flight documentColor request.
DocumentHighlightOutcome
4.4.e: in-flight documentHighlight request outcome.
DocumentLinksOutcome
4.5.c: outcome of an in-flight textDocument/documentLink request. Empty for server responses that returned no links (still updates the cache so we don’t keep re-issuing for the same version).
FoldingRangeOutcome
4.4.f: in-flight foldingRange request outcome.
FormatOutcome
Outcome of a :format / :format-range request. Drained per frame; the App applies the edits as one undo unit or echoes the appropriate failure / no-op state.
HoverOutcome
Result of a K (LSP hover) request, sent from the spawned task to the App’s main thread. Carrying the no-result variants explicitly (instead of just dropping the channel send) lets the drain echo a clear message so the user always gets feedback on K.
InlayHintOutcome
4.4.g: in-flight inlayHint request outcome. The requested_*_line pair rides through so the drain can seat the cache with the range that actually produced these hints (matters for the viewport pump – subsequent scrolls reuse the cache only while the viewport sits inside that range).
LspNavKind
Which navigation request flavour produced an in-flight nav response (Phase 4.2.c). All four share the same dispatch shape (per-server Vec<Location> merge + dedup + jump-or- list) – the kind only changes the LSP method called and the user-facing “no X found” echo.
PullDiagnosticsOutcome
4.4.j: in-flight textDocument/diagnostic request outcome. Full means “here are the diagnostics” (apply to the layer); Unchanged means “nothing moved since the previous result_id” (no-op on the layer, just refresh the cache’s version). Empty is the “no server / cancelled / error” path – still seats a cache entry with the current version so the pump doesn’t re-fire on the next tick without an actual edit.
ReferencesOutcome
Result of a gr (LSP references) request. Carries the symbol-under-cursor verbatim so the rendered help buffer’s title reads References for "foo" and the user has confirmation of what they searched for.
RenameOutcome
Outcome of a :rename request. The success arm pre-flattens the WorkspaceEdit into a per-file Vec<TextEdit> map so the App-side apply path doesn’t have to walk lsp-types’ enum shapes. NoProvider echoes when no attached server advertises renameProvider; NotRenameable when prepareRename refused; Empty when the rename succeeded but the server returned no edits.
SelectionRangeOutcome
4.4.e: outcome of an in-flight textDocument/selectionRange request. The drain consumes one of these per response and either seats the chain into App::lsp_selection_chain or surfaces an error echo. pending_step carries whether the triggering invocation was :lsp-expand-region or the first step of :lsp-shrink-region (the latter is rare – shrink without an existing chain is a user error – but the drain handles it uniformly).
SelectionRangeStep
SemanticTokensOutcome
4.4.h: in-flight semanticTokens/full request outcome. 4.4.i extends with the Delta variant for the full/delta path.
SignatureHelpOutcome
Outcome of a textDocument/signatureHelp request. The response carries multiple signatures (one per overload) plus the active signature/parameter indices. We collapse to the active overload + parameter highlight for the popup body.
SymbolsOutcome
Outcome of a document-symbol / workspace-symbol request – drained per frame and either opens a picker or echoes.

Functions§

apply_semantic_token_edits
4.4.i: apply a server-issued SemanticTokensEdit script to raw_data in place. Each edit specifies a start index (into the previous token vec), a count to delete, and a replacement slice. Edits are applied in order; the server constructs them against the index space of the input vec.
decode_semantic_tokens
4.4.h: decode the LSP semantic-tokens stream into absolute-position tokens. Format per LSP §3.17.6: each token’s delta_line is relative to the previous token’s line; delta_start is relative to the previous token’s start when on the same line, otherwise relative to column 0. token_types / token_modifiers are the server’s legend slices – indexes outside the legend are dropped (defense-in-depth; real servers don’t emit out-of-range).