Skip to main content

CompletionSource

Trait CompletionSource 

Source
pub trait CompletionSource: Send + Sync {
    // Required method
    fn candidates(&self, buffer: &str, cursor: usize) -> Vec<Candidate>;
}
Expand description

Builds the candidate list for the current buffer.

Called on every buffer mutation (typing, paste, backspace) and on explicit terminal-owned refresh requests. An empty result closes the completion menu; a non-empty result opens it (or refreshes it if already open).

Required Methods§

Source

fn candidates(&self, buffer: &str, cursor: usize) -> Vec<Candidate>

Returns whole-buffer completion candidates for buffer.

cursor is a UTF-8 byte offset into buffer, clamped to a grapheme boundary by the prompt before this hook is called. The hook runs synchronously on the input-event path, so implementations should avoid blocking work. Previewing a returned candidate replaces the entire prompt buffer with Candidate::replacement and places the cursor at Candidate::cursor. Accepting it uses Candidate::acceptance when present, otherwise it retains the preview. Sources must provide UTF-8 byte offsets on extended-grapheme boundaries no larger than their replacement lengths; malformed candidates are omitted.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F> CompletionSource for F
where F: Fn(&str, usize) -> Vec<Candidate> + Send + Sync,