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 BufferActive buffer’s rope text. Sources read it via
buffer.line(line_idx) etc.
cursor: PositionCursor position at popup-open time. The popup’s
“current word” is buffer[anchor..cursor].
anchor: PositionAnchor: where the replacement region starts. Same as
InsertCompletionState::anchor.
query: &'a strLive 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 CompletionTriggerWhat triggered the popup.
case_sensitive: boolWhether matching should be case-sensitive. Default matcher honours this.
language: &'a strCSM.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: boolCSM.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.