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§
- Snippet
Active Mode 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>) viaMode::keymap(); K.2.4 registers them at startup underKeymapLayer::MinorMode("active-snippet-mode")and K.1.c gates them to buffers where the mode is active.- Snippet
Active Mode Guard - RAII guard for
SnippetActiveMode. Holds theActionHandlerRegistrationtokens 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 theActionHandlerRegistryso the chord falls through to “unhandled” once no snippet is live. - Snippet
Completion Mode snippet-completion-mode– theModeadapter that contributesSnippetCompletionSourcewhen active. Marker mode otherwise; the contribution is the whole point.- Snippet
Completion Source - The
SyncCompletionSourceimpl that emits snippet candidates. Captures the registry as anArcso cloning the contribution stays O(1); the registry itself is shared with the host’sApp.snippet_registry. - Snippet
Mode 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 itimpliesSnippetCompletionModeso the completion source rides the same gate (activatingsnippet-modebrings 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>.prioritykey off this string. - SNIPPET_
PAYLOAD_ KIND_ ID - Extension-payload kind tag for snippet candidates. Carried
in
RawCandidate::dataso the host’ssnippet_meta_forreader can route the payload back throughSnippetRegistry::by_name. Value matches the host’s historicSNIPPET_COMPLETION_KIND_ID = 2so 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-modeagainstregistryusingsnippet_registryas the contribution-side handle. The App shares the sameArc<SnippetRegistry>with this mode so source produce + host accept-path read the same data. Returns the sharedSnippetActivationPolicyHandlethesnippet-modegate reads. The host stores a clone onEditorand foldssnippet.activation/snippet.languagesinto it at boot + on:set(SN.3b); the default cell value isActivationPolicy::Global.
Type Aliases§
- Shared
Snippet Registry - Shared handle to a swappable snippet registry. The App owns
one
Arc<SharedSnippetRegistry>; the mode + source capture clones of the outerArc.:reload-snippetscalls.store()on the innerArcSwap– the mode keeps reading via the outer handle and sees the fresh data on the nextproduce().