Skip to main content

InsertContext

Struct InsertContext 

Source
pub struct InsertContext<'a> {
    pub buffer: &'a Buffer,
    pub cursor: Position,
    pub anchor: Position,
    pub query: &'a str,
    pub trigger: &'a CompletionTrigger,
    pub case_sensitive: bool,
    pub language: &'a str,
    pub tree_sitter_symbols: &'a [String],
    pub path_context: bool,
    pub buffer_dir: Option<&'a Path>,
    pub uri: Option<&'a str>,
    pub lsp_position: Option<(u32, u32)>,
}
Expand description

Snapshot of editor state a source reads when producing candidates. Held by reference so the aggregator borrows from the surrounding frame for the duration of produce().

Sources that need richer state (the LSP source needs the ServerHandle, the snippet source needs the per-language snippet registry) get those out-of-band – they’re not part of the generic context.

Fields§

§buffer: &'a Buffer

Active buffer’s rope text. Sources read it via buffer.line(line_idx) etc.

§cursor: Position

Cursor position at popup-open time. The popup’s “current word” is buffer[anchor..cursor].

§anchor: Position

Anchor: where the replacement region starts. Same as InsertCompletionState::anchor.

§query: &'a str

Live filter text – buffer[anchor..cursor]. Sources can use this to filter their own output (snippet source looks up by prefix, e.g.) but the aggregator’s matcher also filters globally so sources don’t strictly need to.

§trigger: &'a CompletionTrigger

What triggered the popup.

§case_sensitive: bool

Whether matching should be case-sensitive. Default matcher honours this.

§language: &'a str

CSM.5: active buffer’s language id (e.g. "rust", "markdown"). The snippet source filters its registry by language; tree-sitter / LSP / dictionary sources may branch on it too. Empty string when no language is detected (plain-text buffer); sources should treat empty + the literal "*" as the catch-all bucket.

§tree_sitter_symbols: &'a [String]

CSM.6: pre-computed local-symbol identifiers from the buffer’s tree-sitter parse (function names, struct names, let bindings, parameters – whatever the language’s symbols.scm query selects). Empty when no syntax handle is attached or the language ships no query. The host walks collect_symbols() once per populate / refilter; the tree-sitter source iterates this slice without re-traversing the tree.

§path_context: bool

CSM.7: true when the cursor sits inside a string scope (host-detected via the active buffer’s tree-sitter parse). The path source produces candidates only when this is true – outside a string literal, file-name completion would interleave with prose / code and surprise the user. Defaults to false; the host sets it from App.completion_in_path_context.

§buffer_dir: Option<&'a Path>

CSM.7: pre-resolved base directory for the path source’s filesystem walk. The host computes this from the active document’s parent (or std::env::current_dir() for unsaved buffers); the source joins relative path segments onto it. None when no usable base resolved (the source skips the walk in that case).

§uri: Option<&'a str>

CSM.8b: generic buffer URI as a string (e.g. file:///path/to/file.rs). None for scratch / unsaved buffers. The LSP source parses it back into an lsp_types::Uri; other sources ignore.

§lsp_position: Option<(u32, u32)>

CSM.8b: pre-computed LSP position (line, character) in UTF-16 encoding. Populated when the host has an LSP server attached and the URI is known; the LSP source uses it to build lsp_types::Position without re-running the conversion. None when LSP isn’t applicable to this buffer.

Auto Trait Implementations§

§

impl<'a> Freeze for InsertContext<'a>

§

impl<'a> RefUnwindSafe for InsertContext<'a>

§

impl<'a> Send for InsertContext<'a>

§

impl<'a> Sync for InsertContext<'a>

§

impl<'a> Unpin for InsertContext<'a>

§

impl<'a> UnsafeUnpin for InsertContext<'a>

§

impl<'a> UnwindSafe for InsertContext<'a>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more