Compare commits
1 commit
main
...
gabritto/s
Author | SHA1 | Date | |
---|---|---|---|
a52b84feeb |
|
@ -1942,6 +1942,11 @@ namespace ts {
|
|||
case SnippetKind.TabStop:
|
||||
emitTabStop(snippet);
|
||||
break;
|
||||
case SnippetKind.Sequence:
|
||||
emitSequence(snippet);
|
||||
break;
|
||||
default:
|
||||
return Debug.fail("Unsupported SnippetKind.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1956,6 +1961,12 @@ namespace ts {
|
|||
nonEscapingWrite(`\$${snippet.order}`);
|
||||
}
|
||||
|
||||
function emitSequence(snippet: SnippetSequence) {
|
||||
for (const s of snippet.snippets) {
|
||||
emitTabStop(s);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Identifiers
|
||||
//
|
||||
|
|
|
@ -6828,7 +6828,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
/* @internal */
|
||||
export type SnippetElement = TabStop | Placeholder;
|
||||
export type SnippetElement = TabStop | Placeholder | SnippetSequence;
|
||||
|
||||
/* @internal */
|
||||
export interface TabStop {
|
||||
|
@ -6842,6 +6842,12 @@ namespace ts {
|
|||
order: number;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export interface SnippetSequence {
|
||||
kind: SnippetKind.Sequence;
|
||||
snippets: TabStop[];
|
||||
}
|
||||
|
||||
// Reference: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax
|
||||
/* @internal */
|
||||
export const enum SnippetKind {
|
||||
|
@ -6849,6 +6855,7 @@ namespace ts {
|
|||
Placeholder, // `${1:foo}`
|
||||
Choice, // `${1|one,two,three|}`
|
||||
Variable, // `$name`, `${name:default}`
|
||||
Sequence, // A sequence of tabstops, e.g. `$1$0`
|
||||
}
|
||||
|
||||
export const enum EmitFlags {
|
||||
|
|
|
@ -852,12 +852,19 @@ namespace ts.Completions {
|
|||
let tabstopStart = 1;
|
||||
if (preferences.includeCompletionsWithSnippetText) {
|
||||
isSnippet = true;
|
||||
// We are adding a final tabstop (i.e. $0) in the body of the suggested member, if it has one.
|
||||
// We are adding an initial and final tabstop (i.e. `$1$0`) in the body of the suggested member,
|
||||
// if it has one.
|
||||
// Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
|
||||
const emptyStatement1 = factory.createExpressionStatement(factory.createIdentifier(""));
|
||||
setSnippetElement(emptyStatement1, { kind: SnippetKind.TabStop, order: 1 });
|
||||
const emptyStatement = factory.createExpressionStatement(factory.createIdentifier(""));
|
||||
setSnippetElement(emptyStatement, {
|
||||
kind: SnippetKind.Sequence,
|
||||
snippets: [
|
||||
{ kind: SnippetKind.TabStop, order: 1 },
|
||||
{ kind: SnippetKind.TabStop, order: 0 },
|
||||
],
|
||||
});
|
||||
tabstopStart = 2;
|
||||
body = factory.createBlock([emptyStatement1], /* multiline */ true);
|
||||
body = factory.createBlock([emptyStatement], /* multiline */ true);
|
||||
}
|
||||
else {
|
||||
body = factory.createBlock([], /* multiline */ true);
|
||||
|
|
|
@ -30,7 +30,7 @@ verify.completions({
|
|||
},
|
||||
isSnippet: true,
|
||||
insertText:
|
||||
"\"\\$usd\"(${2:a}: ${3:number}): ${4:number} {\n $1\n}\n",
|
||||
"\"\\$usd\"(${2:a}: ${3:number}): ${4:number} {\n $1$0\n}\n",
|
||||
}
|
||||
],
|
||||
});
|
Loading…
Reference in a new issue