Skip to main content

Module completion

Module completion 

Source
Expand description

Completion-mode pair (insert-completion.md §12).

The completion machinery surfaces through two minors with different lifecycles:

  • completion-mode – “this buffer participates in insert-mode completion.” Auto-activates on writable buffer kinds (Document) at buffer creation; stays active for the buffer’s lifetime. Acts as the gate do_completion_trigger checks before opening the popup – read-only kinds (Help, FileTree, Oil) never activate it, so <C-Space> in those buffers is a silent no-op.

  • completion-popup-mode – transient. Active iff the candidate popup is live. Owns the popup-internal keymap (<C-n> / <C-p> / <C-y> / <Tab> / <CR> / <Esc> / <C-e> / <C-d> / <C-Space> / <C-f> / <C-b> plus the per-source filter chords from CSM.K2). Replaces the imperative App.insert_completion.is_some() flag the v1 wiring gated on (CSM.2’s original completion-mode).

Both modes own no contributed options today. The pairing mirrors lsp-mode (umbrella, persistent) + the LSP sub-modes (per-feature, persistent) – here the lifecycle distinction is “persistent on writable buffers” vs “transient with the popup.”

Placement: in lattice-mode::modes (not lattice-completion) to avoid a dep cycle – lattice-mode already depends on lattice-completion for the CompletionSourceContribution return type on Mode::completion_sources() (CSM.1), so reversing direction would require Mode itself to live in completion.

Structs§

ActiveCompletionSources
Cached active completion- source set for a buffer. The host (App::recompute_active_completion_sources_for) recomputes this on every mode-activation / -deactivation transition by walking active_modes and calling mode.completion_sources() on each. The aggregator reads the cache on the popup-open / refilter path – O(1) buffer- local lookup, never a walk over every active mode per keystroke (CSM.3, insert-completion.md §12.4).
BufferWordsMode
CSM.4 (insert-completion.md §12 first source migration): buffer-words-mode – contributes the buffer-words completion source. Auto-activates on writable buffer kinds (Document) so the popup’s all-sources view shows words scraped from the active buffer’s text. popup_filter_chord = Some('b') ⇒ <C-b> inside completion-popup-mode narrows the popup to buffer-words only.
CompletionMode
The “buffer participates in insert-mode completion” marker. Auto-activates on writable kinds at buffer creation. See module docs.
CompletionPopupMode
The popup-is-live transient minor. See module docs.
PathCompletionMode
CSM.7 (insert-completion.md §12 fourth source migration): path-completion-mode – contributes the path-completion source. Auto-activates on writable buffer kinds; the source self-suppresses outside string scopes (gated by ctx.path_context which the host sets from its tree-sitter scope detection). popup_filter_chord = Some('f') ⇒ <C-f> inside completion-popup-mode narrows the popup to filesystem entries only.