Skip to main content

Module modes

Module modes 

Source
Expand description

snippet-completion-mode (insert-completion.md §12, CSM.5).

The Mode adapter + SyncCompletionSource impl that turn the snippet registry into a first-class completion source. Auto-activates on writable buffer kinds via auto_activated_minors_for_buffer_kind in lattice-ui-tui::modes; the source’s contribution flows through CSM.3’s ActiveCompletionSources cache and populates the popup alongside buffer-words / tree-sitter / LSP candidates.

Placement: lattice-snippet is a leaf in the dep graph (neither lattice-mode nor lattice-completion depend on it), so adding lattice-mode + lattice-completion as upstream deps doesn’t create a cycle. The mode + source live together in the feature crate – the placement the mode-architecture rule asks for.

Structs§

SnippetActiveMode
active-snippet-mode — a transient minor mode activated while a snippet session is live on a buffer. Contributes the three Insert-mode bindings (<Tab> / <S-Tab> / <Esc>) via Mode::keymap(); K.2.4 registers them at startup under KeymapLayer::MinorMode("active-snippet-mode") and K.1.c gates them to buffers where the mode is active.
SnippetActiveModeGuard
RAII guard for SnippetActiveMode. Holds the ActionHandlerRegistration tokens for the <Tab> / <S-Tab> / <Esc> handlers (SN.3c.2 added <Esc>); dropping it (on mode deactivation) drops the tokens, each of which unregisters its closure from the ActionHandlerRegistry so the chord falls through to “unhandled” once no snippet is live.
SnippetCompletionMode
snippet-completion-mode – the Mode adapter that contributes SnippetCompletionSource when active. Marker mode otherwise; the contribution is the whole point.
SnippetCompletionSource
The SyncCompletionSource impl that emits snippet candidates. Captures the registry as an Arc so cloning the contribution stays O(1); the registry itself is shared with the host’s App.snippet_registry.
SnippetMode
snippet-mode — the base “snippets enabled for this buffer” minor mode (SN.3). The language-aware feature gate: its [ActivationPolicy] decides which buffers get snippets, and it implies SnippetCompletionMode so the completion source rides the same gate (activating snippet-mode brings the source with it — no separate activation).

Constants§

SNIPPET_COMPLETION_SOURCE_ID
Stable id for the snippet completion source. Must match lattice_completion::SNIPPET_SOURCE_ID – the host’s per-language allowlist + :set completion.source.<id>.priority key off this string.
SNIPPET_PAYLOAD_KIND_ID
Extension-payload kind tag for snippet candidates. Carried in RawCandidate::data so the host’s snippet_meta_for reader can route the payload back through SnippetRegistry::by_name. Value matches the host’s historic SNIPPET_COMPLETION_KIND_ID = 2 so the existing accept path keeps recognising snippet candidates without a flag day. Stable u32 – changing it breaks every snippet candidate’s accept path.

Functions§

register_snippet_modes
Register snippet-completion-mode against registry using snippet_registry as the contribution-side handle. The App shares the same Arc<SnippetRegistry> with this mode so source produce + host accept-path read the same data. Returns the shared SnippetActivationPolicyHandle the snippet-mode gate reads. The host stores a clone on Editor and folds snippet.activation / snippet.languages into it at boot + on :set (SN.3b); the default cell value is ActivationPolicy::Global.

Type Aliases§

SharedSnippetRegistry
Shared handle to a swappable snippet registry. The App owns one Arc<SharedSnippetRegistry>; the mode + source capture clones of the outer Arc. :reload-snippets calls .store() on the inner ArcSwap – the mode keeps reading via the outer handle and sees the fresh data on the next produce().