pub struct Snippet {
pub text: String,
pub stops: Vec<TabStop>,
}Expand description
A parsed snippet: the body with every placeholder’s default expanded, plus the tab stops to visit.
Fields§
§text: StringThe body with placeholders replaced by their default text. LF-normal
already (the caller’s expander normalizes EOL and adapts \t indent at
insert time); this parser leaves \t literal.
stops: Vec<TabStop>Stops in visit order: ascending placeholder index, the final stop last.
Implementations§
Source§impl Snippet
impl Snippet
Sourcepub fn for_insertion(&self, indent: &str, indent_size: usize) -> Snippet
pub fn for_insertion(&self, indent: &str, indent_size: usize) -> Snippet
Adapt a parsed snippet for insertion at a line whose leading whitespace is
indent (captured pre-edit), expanding tabs to indent_size spaces — the
insertion transform (pure text; no transaction machinery):
- EOL-normalize (
\r\n/\r→\n); - every
\n→\n+indent, so continuation lines align with the insertion column (spec.rs bodies are written flush-left); - every
\t→indent_sizespaces (one indent unit); - stop ranges remap through the same rewrite.
The caret lands at the final stop; the returned stop ranges are relative
to the returned text, which the caller inserts as one transaction.
Sourcepub fn parse(body: &str) -> Result<Self, SnippetError>
pub fn parse(body: &str) -> Result<Self, SnippetError>
Parse an LSP placeholder body (see the module grammar).
§Errors
SnippetError on a duplicate index, a nested placeholder in a default,
or a malformed ${…} token.
Trait Implementations§
impl Eq for Snippet
impl StructuralPartialEq for Snippet
Auto Trait Implementations§
impl Freeze for Snippet
impl RefUnwindSafe for Snippet
impl Send for Snippet
impl Sync for Snippet
impl Unpin for Snippet
impl UnsafeUnpin for Snippet
impl UnwindSafe for Snippet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.