Skip to main content

lattice_snippet/
lib.rs

1//! TextMate-format snippet engine for lattice
2//! (Phase 4.2.g.4; design in
3//! [`docs/dev/architecture/insert-completion.md`](../../docs/dev/architecture/insert-completion.md) ยง8).
4//!
5//! Three responsibilities:
6//!
7//! 1. **Parse** TextMate / LSP snippet body syntax (placeholders,
8//!    choices, variables, escapes) into a stream of [`SnippetToken`]s.
9//! 2. **Render** that stream into the literal text the editor
10//!    inserts plus the per-tabstop byte ranges
11//!    ([`RenderedSnippet`]) -- so the host can wire placeholder
12//!    navigation without re-parsing.
13//! 3. **Track** the in-flight snippet expansion's tabstop state
14//!    via [`ActiveSnippet`] so `<Tab>` / `<S-Tab>` step through
15//!    placeholders and edits in one tabstop ripple to its
16//!    mirrors.
17//!
18//! Drop-in compatibility with the **VS Code TextMate JSON
19//! format** is the design target: `friendly-snippets` (the
20//! community-maintained corpus most editors pull from) loads
21//! verbatim. See [`load`] for the JSON ingestion path and
22//! [`registry::SnippetRegistry`] for per-language storage.
23//!
24//! Variables are resolved against an editor-supplied
25//! [`VariableContext`] -- the host fills in `TM_FILENAME` /
26//! `CLIPBOARD` / etc. when the snippet expands. v1 supports the
27//! TextMate / VS Code built-in variable set; transformation
28//! placeholders (`${1/pattern/replacement/}`) parse to a
29//! transformation token but apply as their original text in
30//! v1; full regex transformation lands as polish.
31//!
32//! This crate has **no editor dependency**. Tests parse + render +
33//! drive the active-snippet state machine without touching
34//! any rope or buffer; the host wires [`ActiveSnippet`] to its
35//! buffer-mutation pipeline.
36
37pub mod activation;
38pub mod active;
39pub mod builtins;
40pub mod load;
41pub mod modes;
42pub mod parse;
43pub mod picker_sources;
44pub mod registry;
45pub mod render;
46pub mod session;
47pub mod token;
48pub mod variables;
49
50pub use crate::activation::{
51    SnippetActivation, SnippetActivationMode, SnippetActivationPolicyHandle, SnippetLanguages,
52    fold_activation_policy,
53};
54pub use crate::active::{ActiveSnippet, TabstopGroup};
55pub use crate::builtins::{builtin_packs, load_builtins, load_builtins_into};
56pub use crate::load::{LoadError, load_pack, load_pack_from_str};
57pub use crate::modes::{
58    SNIPPET_COMPLETION_SOURCE_ID, SNIPPET_PAYLOAD_KIND_ID, SnippetCompletionMode,
59    SnippetCompletionSource, SnippetMode, register_snippet_modes,
60};
61pub use crate::parse::{ParseError, parse};
62pub use crate::registry::{Snippet, SnippetMeta, SnippetRegistry};
63pub use crate::render::{RenderedSnippet, TabstopRange};
64pub use crate::session::{SnippetSession, SnippetSessionHandle, snippet_active_predicate};
65pub use crate::token::{ChoiceOption, SnippetBody, SnippetToken};
66pub use crate::variables::{VariableContext, builtin_variables};