pub struct CompletionController { /* private fields */ }Expand description
The completion controller. Holds only the popup state; the document, provider, and caret are supplied by the caller per event.
Implementations§
Source§impl CompletionController
impl CompletionController
Sourcepub fn state(&self) -> &CompletionState
pub fn state(&self) -> &CompletionState
The current state (for the widget to render).
Sourcepub fn on_input(
&mut self,
cx: &CompletionCx,
word: &str,
provider: &mut dyn Completions,
)
pub fn on_input( &mut self, cx: &CompletionCx, word: &str, provider: &mut dyn Completions, )
Drive the machine on a completion-relevant keystroke, per cx.trigger:
a trigger char / Ctrl+Space requests fresh items in any state (even
while dismissed); a word char opens from Closed, refilters locally
while Open (no provider call), and is ignored while dismissed. word is
the live completion-word text under the caret. Calls provider.complete
at most once per event.
Sourcepub fn set_items(&mut self, items: Vec<CompletionItem>, word: &str, anchor: u32)
pub fn set_items(&mut self, items: Vec<CompletionItem>, word: &str, anchor: u32)
Ingest an externally-produced item list — an off-thread or
language-server completion result — as if a provider had returned it:
open and filter against the live word (with anchor the word start),
or close if nothing matches. The controller stays document-agnostic; the
caller is responsible for staleness (only call with results computed at
the current revision, refiltered here against the current word so a
result that arrives after the user typed more still filters correctly).
Sourcepub fn on_boundary(&mut self)
pub fn on_boundary(&mut self)
A word boundary was crossed (a non-word / non-trigger char, or backspacing out of the word) — clears Escape-stickiness so the next word can reopen.
Sourcepub fn set_selected(&mut self, index: u32)
pub fn set_selected(&mut self, index: u32)
Set the selected row to index (a filtered-list index), clamped; no-op
when closed. Used by a popup row click.
Sourcepub fn move_selection(&mut self, down: bool)
pub fn move_selection(&mut self, down: bool)
Move the selection (Up/Down) with wrap; no-op when closed.
Sourcepub fn escape(&mut self) -> bool
pub fn escape(&mut self) -> bool
Escape while open → sticky-dismiss; returns whether the event was captured (so the widget knows not to let Escape fall through to other handlers).
Sourcepub fn accept(&mut self) -> Option<CompletionItem>
pub fn accept(&mut self) -> Option<CompletionItem>
Accept the selected item: returns it (cloned) and closes the popup. The
caller applies it as one sealed transaction — replace range = the item’s
replace, else the live completion word — and, if retrigger, fires one
Manual on_input. Returns None when not open / nothing selected.