Table of Contents

Class Snippet

Namespace
RDCore.SDK.Formatting
Assembly
RDCore.SDK.dll

The text a snippet is inserted as, and the places in it an editor's cursor stops at (LSP 3.17 §Snippet Syntax): what a completion item whose insertTextFormat is Snippet inserts.

public sealed record Snippet : IEquatable<Snippet>
Inheritance
Snippet
Implements
Inherited Members

Remarks

A tab stop ($1, ${1}) is where the cursor stops; a placeholder (${1:name}) is a tab stop with the text it starts with, which may hold other tab stops (${1:Dim ${2:x}}). A choice (${1|ByVal,ByRef|}) is the placeholder of its first option. A tab stop whose number is used more than once is one tab stop in several places: each of them shows the placeholder it is given in any of them - the first one, in the order of the text - with the tab stops that placeholder holds. A transform (${1/(.*)/$1/}) is not made: the tab stop is the one it transforms.

A variable ($TM_SELECTED_TEXT, ${TM_FILENAME:default}) is its value, or its default when it has none. The variables an editor is said to know (TM_SELECTED_TEXT, TM_CURRENT_LINE, TM_CURRENT_WORD, TM_LINE_INDEX, TM_LINE_NUMBER, TM_FILENAME, TM_FILENAME_BASE, TM_DIRECTORY, TM_FILEPATH) are empty unless the caller says what they are; a variable that is none of them and that the caller does not know, with no default, is its name, a tab stop of its own after the numbered ones, as the protocol has it. A variable's transform is not made.

A \ escapes a $, a } or a \ - and, in a choice, a , or a |. What does not read as a tab stop, a placeholder, a choice or a variable - a placeholder that is not closed, a choice with a | in an option - is the text it is.

Constructors

Snippet(string, IReadOnlyList<SnippetTabStop>)

The text a snippet is inserted as, and the places in it an editor's cursor stops at (LSP 3.17 §Snippet Syntax): what a completion item whose insertTextFormat is Snippet inserts.

public Snippet(string Text, IReadOnlyList<SnippetTabStop> TabStops)

Parameters

Text string

The text the snippet is inserted as.

TabStops IReadOnlyList<SnippetTabStop>

The places of its tab stops in Text, in the order of the text.

Remarks

A tab stop ($1, ${1}) is where the cursor stops; a placeholder (${1:name}) is a tab stop with the text it starts with, which may hold other tab stops (${1:Dim ${2:x}}). A choice (${1|ByVal,ByRef|}) is the placeholder of its first option. A tab stop whose number is used more than once is one tab stop in several places: each of them shows the placeholder it is given in any of them - the first one, in the order of the text - with the tab stops that placeholder holds. A transform (${1/(.*)/$1/}) is not made: the tab stop is the one it transforms.

A variable ($TM_SELECTED_TEXT, ${TM_FILENAME:default}) is its value, or its default when it has none. The variables an editor is said to know (TM_SELECTED_TEXT, TM_CURRENT_LINE, TM_CURRENT_WORD, TM_LINE_INDEX, TM_LINE_NUMBER, TM_FILENAME, TM_FILENAME_BASE, TM_DIRECTORY, TM_FILEPATH) are empty unless the caller says what they are; a variable that is none of them and that the caller does not know, with no default, is its name, a tab stop of its own after the numbered ones, as the protocol has it. A variable's transform is not made.

A \ escapes a $, a } or a \ - and, in a choice, a , or a |. What does not read as a tab stop, a placeholder, a choice or a variable - a placeholder that is not closed, a choice with a | in an option - is the text it is.

Fields

MostNested

The most placeholders a snippet has in one another - written so, or shown so through the tab stops they hold - before it is no snippet to insert. A tab stop in a placeholder of its own, at any depth (${1:a $2} ${2:b $1}), shows nothing there.

public const int MostNested = 16

Field Value

int

MostTabStops

The most places of tab stops a snippet has once it is written.

public const int MostTabStops = 4096

Field Value

int

MostText

The most characters a snippet is written as; one whose placeholders, shown in one another, make more is not a snippet to insert.

public const int MostText = 65536

Field Value

int

Properties

IsMultiline

Whether the snippet is more than one line.

public bool IsMultiline { get; }

Property Value

bool

TabStops

The places of its tab stops in Text, in the order of the text.

public IReadOnlyList<SnippetTabStop> TabStops { get; init; }

Property Value

IReadOnlyList<SnippetTabStop>

Text

The text the snippet is inserted as.

public string Text { get; init; }

Property Value

string

Methods

Parse(string, Func<string, string?>?)

The text and the tab stops of a snippet.

public static Snippet Parse(string snippet, Func<string, string?>? variables = null)

Parameters

snippet string

The snippet, as LSP 3.17 writes it.

variables Func<string, string>

The value of a variable by its name; null for one the caller does not know. Without it, the variables an editor is said to know are empty, and the others are not known.

Returns

Snippet

Exceptions

ArgumentNullException

snippet is null.

ArgumentException

The snippet, written, is more than MostText characters or MostTabStops places of tab stops (TryParse(string, out Snippet?, Func<string, string?>?)).

TryParse(string, out Snippet?, Func<string, string?>?)

The text and the tab stops of a snippet, unless it is larger once it is written - its placeholders shown in one another - than a snippet to insert is: MostText characters, MostTabStops places of tab stops.

public static bool TryParse(string snippet, out Snippet? parsed, Func<string, string?>? variables = null)

Parameters

snippet string

The snippet, as LSP 3.17 writes it.

parsed Snippet

The snippet; null when it is larger.

variables Func<string, string>

The value of a variable by its name, as for Parse(string, Func<string, string?>?).

Returns

bool

Whether the snippet is one to insert.

Exceptions

ArgumentNullException

snippet is null.