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
Bufferclone isO(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 capturesArc<SnippetRegistry>).
Fields§
§cursor: Position§anchor: Position§query: String§trigger: CompletionTrigger§case_sensitive: bool§language: StringActive 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: boolCursor 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: StringOR.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
impl InsertContextSnapshot
Sourcepub fn from_context(ctx: &InsertContext<'_>) -> Self
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
impl Clone for InsertContextSnapshot
Source§fn clone(&self) -> InsertContextSnapshot
fn clone(&self) -> InsertContextSnapshot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more