Skip to main content

InsertContextSnapshot

Struct InsertContextSnapshot 

Source
pub struct InsertContextSnapshot {
    pub cursor: Position,
    pub anchor: Position,
    pub query: String,
    pub trigger: CompletionTrigger,
    pub case_sensitive: bool,
    pub language: String,
    pub tree_sitter_symbols: Vec<String>,
    pub path_context: bool,
    pub buffer_dir: Option<PathBuf>,
    pub uri: Option<String>,
    pub line_before_cursor: String,
    pub lsp_position: Option<(u32, u32)>,
}
Expand description

Owned snapshot of InsertContext for crossing the spawn / future boundary. The borrowed crate::insert::InsertContext can’t cross the spawn (it holds &Buffer / &str); the snapshot copies the fields the source actually needs.

CSM.1 ships the minimal snapshot (cursor / anchor / query / trigger / case-sensitivity). Sources that need richer context (e.g. tree-sitter walking the buffer’s syntax tree) will either:

  • extend this struct with the relevant owned field (a Buffer clone is O(1) thanks to ropey’s structural sharing);
  • or capture the data they need through their own struct’s fields at construction (the LSP source captures LspSupervisorHandle, the snippet source captures Arc<SnippetRegistry>).

Fields§

§cursor: Position§anchor: Position§query: String§trigger: CompletionTrigger§case_sensitive: bool§language: String

Active buffer’s language id (CSM.5). See InsertContext::language.

§tree_sitter_symbols: Vec<String>

Pre-computed tree-sitter symbols (CSM.6). See InsertContext::tree_sitter_symbols.

§path_context: bool

Cursor sits inside a string scope (CSM.7). See InsertContext::path_context.

§buffer_dir: Option<PathBuf>

Base directory for path-source filesystem walks (CSM.7). See InsertContext::buffer_dir.

§uri: Option<String>

CSM.8b: generic buffer URI as a string. Populated by the host when the active buffer maps to a filesystem (or virtual) URI; None for scratch / unsaved buffers. The LSP source parses it back via lsp_types::Uri::from_str.

§line_before_cursor: String

OR.7: the text from the start of the cursor’s line up to the cursor, verbatim. The one field that lets an out-of-process source decide whether it applies at all without the host growing a per-source context flag.

path_context above is the shape this replaces: a bool the host computes on one source’s behalf, so teaching the host a new context means teaching it that source’s syntax. A source that only fires inside [[…]] (org-roam links), after #+ (org keywords), or inside a fenced block reads this string and answers for itself; the host stays ignorant of every one of those. Native sources have buffer and never need it — this exists for the WASM seam, which has only what crosses.

Note what it does NOT change: the popup’s replacement region is still [anchor, cursor], computed once at open. A source whose candidates would replace more than that must decline unless the anchor already covers what it means to replace — which it can now check, because it can see the text between the two.

§lsp_position: Option<(u32, u32)>

CSM.8b: pre-computed LSP position (line, character) in UTF-16 encoding. Populated by the host when an LSP server is attached and the buffer’s URI is known. The source uses it directly to build lsp_types::Position; sources that need a different encoding ignore this.

Implementations§

Source§

impl InsertContextSnapshot

Source

pub fn from_context(ctx: &InsertContext<'_>) -> Self

Take an owned snapshot of ctx. Cheap-ish – clones query + language + the tree_sitter_symbols slice; the other fields are Copy.

Trait Implementations§

Source§

impl Clone for InsertContextSnapshot

Source§

fn clone(&self) -> InsertContextSnapshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InsertContextSnapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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