Expand description
TextMate-format snippet engine for lattice
(Phase 4.2.g.4; design in
docs/dev/architecture/insert-completion.md §8).
Three responsibilities:
- Parse TextMate / LSP snippet body syntax (placeholders,
choices, variables, escapes) into a stream of
SnippetTokens. - Render that stream into the literal text the editor
inserts plus the per-tabstop byte ranges
(
RenderedSnippet) – so the host can wire placeholder navigation without re-parsing. - Track the in-flight snippet expansion’s tabstop state
via
ActiveSnippetso<Tab>/<S-Tab>step through placeholders and edits in one tabstop ripple to its mirrors.
Drop-in compatibility with the VS Code TextMate JSON
format is the design target: friendly-snippets (the
community-maintained corpus most editors pull from) loads
verbatim. See load for the JSON ingestion path and
registry::SnippetRegistry for per-language storage.
Variables are resolved against an editor-supplied
VariableContext – the host fills in TM_FILENAME /
CLIPBOARD / etc. when the snippet expands. v1 supports the
TextMate / VS Code built-in variable set; transformation
placeholders (${1/pattern/replacement/}) parse to a
transformation token but apply as their original text in
v1; full regex transformation lands as polish.
This crate has no editor dependency. Tests parse + render +
drive the active-snippet state machine without touching
any rope or buffer; the host wires ActiveSnippet to its
buffer-mutation pipeline.
Re-exports§
pub use crate::activation::SnippetActivation;pub use crate::activation::SnippetActivationMode;pub use crate::activation::SnippetActivationPolicyHandle;pub use crate::activation::SnippetLanguages;pub use crate::activation::fold_activation_policy;pub use crate::active::ActiveSnippet;pub use crate::active::TabstopGroup;pub use crate::builtins::builtin_packs;pub use crate::builtins::load_builtins;pub use crate::builtins::load_builtins_into;pub use crate::load::LoadError;pub use crate::load::load_pack;pub use crate::load::load_pack_from_str;pub use crate::modes::SNIPPET_COMPLETION_SOURCE_ID;pub use crate::modes::SNIPPET_PAYLOAD_KIND_ID;pub use crate::modes::SnippetCompletionMode;pub use crate::modes::SnippetCompletionSource;pub use crate::modes::SnippetMode;pub use crate::modes::register_snippet_modes;pub use crate::parse::ParseError;pub use crate::parse::parse;pub use crate::registry::Snippet;pub use crate::registry::SnippetMeta;pub use crate::registry::SnippetRegistry;pub use crate::render::RenderedSnippet;pub use crate::render::TabstopRange;pub use crate::session::SnippetSession;pub use crate::session::SnippetSessionHandle;pub use crate::session::snippet_active_predicate;pub use crate::token::ChoiceOption;pub use crate::token::SnippetBody;pub use crate::token::SnippetToken;pub use crate::variables::VariableContext;pub use crate::variables::builtin_variables;
Modules§
- activation
- SN.3b — config-driven snippet activation policy.
- active
- Active-snippet state machine. The host instantiates one
ActiveSnippetwhen a snippet expands; while it’s the “active” snippet,<Tab>/<S-Tab>step through placeholders and edits to one tabstop ripple to the others that share its index. - builtins
- Built-in snippet packs embedded in the binary.
- load
- TextMate JSON loader – the format VS Code uses and
friendly-snippetsships in. Reading a friendly-snippets pack is a matter of pointing at its JSON files; no conversion or shim code. - modes
snippet-completion-mode(insert-completion.md §12, CSM.5).- parse
- TextMate / LSP snippet body parser. Produces a
SnippetBodyfrom a string; consumers (renderer + active-snippet state machine) walk the resulting tokens. - picker_
sources :picker snippetssource generator.- registry
- Per-language snippet registry. Stores parsed bodies
keyed by trigger prefix; the host’s
gen:snippetsource consults this registry per-popup-trigger. - render
- Render a parsed
SnippetBodyto literal text plus per-tabstop byte ranges. Output feeds the editor’s edit pipeline (insert the text, then track the ranges as the user types into placeholders). - session
- SN.2: the live snippet-expansion session, relocated off the host
Editorso the mode-owned placeholder-navigation handlers can reach it. - token
- Parsed snippet body: the token stream a
crate::parse::parseproduces andcrate::render::renderwalks. - variables
- Variable resolution for snippet expansion. The host fills
in a
VariableContextwith file / cursor / clipboard info; the renderer asks the context for each$VARit encounters.