Skip to main content

CompletionController

Struct CompletionController 

Source
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

Source

pub fn new() -> Self

A fresh, closed controller.

Source

pub fn state(&self) -> &CompletionState

The current state (for the widget to render).

Source

pub fn is_open(&self) -> bool

Whether a popup is showing.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn move_selection(&mut self, down: bool)

Move the selection (Up/Down) with wrap; no-op when closed.

Source

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).

Source

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.

Source

pub fn close(&mut self)

Hard close — a caret move not caused by typing (arrow/click/find-jump), focus loss, set_text, or undo/redo. Idempotent.

Trait Implementations§

Source§

impl Default for CompletionController

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.