mirror of
https://github.com/Microsoft/vscode
synced 2024-10-12 22:37:41 +00:00
Merge pull request #84048 from okmttdhr/snippet-choice-builder-method
Add builder-method for snippet choice
This commit is contained in:
commit
0a0f2bffe5
11
src/vs/vscode.d.ts
vendored
11
src/vs/vscode.d.ts
vendored
|
@ -2967,6 +2967,17 @@ declare module 'vscode' {
|
|||
*/
|
||||
appendPlaceholder(value: string | ((snippet: SnippetString) => any), number?: number): SnippetString;
|
||||
|
||||
/**
|
||||
* Builder-function that appends a choice (`${1|a,b,c}`) to
|
||||
* the [`value`](#SnippetString.value) of this snippet string.
|
||||
*
|
||||
* @param values The values for choices - the array of strings
|
||||
* @param number The number of this tabstop, defaults to an auto-increment
|
||||
* value starting at 1.
|
||||
* @return This snippet string.
|
||||
*/
|
||||
appendChoice(values: string[], number?: number): SnippetString;
|
||||
|
||||
/**
|
||||
* Builder-function that appends a variable (`${VAR}`) to
|
||||
* the [`value`](#SnippetString.value) of this snippet string.
|
||||
|
|
|
@ -740,6 +740,18 @@ export class SnippetString {
|
|||
return this;
|
||||
}
|
||||
|
||||
appendChoice(values: string[], number: number = this._tabstop++): SnippetString {
|
||||
const value = SnippetString._escape(values.toString());
|
||||
|
||||
this.value += '${';
|
||||
this.value += number;
|
||||
this.value += '|';
|
||||
this.value += value;
|
||||
this.value += '|}';
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
appendVariable(name: string, defaultValue?: string | ((snippet: SnippetString) => any)): SnippetString {
|
||||
|
||||
if (typeof defaultValue === 'function') {
|
||||
|
|
|
@ -527,6 +527,25 @@ suite('ExtHostTypes', function () {
|
|||
string.appendVariable('BAR', b => { });
|
||||
assert.equal(string.value, '${BAR}');
|
||||
|
||||
string = new types.SnippetString();
|
||||
string.appendChoice(['b', 'a', 'r']);
|
||||
assert.equal(string.value, '${1|b,a,r|}');
|
||||
|
||||
string = new types.SnippetString();
|
||||
string.appendChoice(['b', 'a', 'r'], 0);
|
||||
assert.equal(string.value, '${0|b,a,r|}');
|
||||
|
||||
string = new types.SnippetString();
|
||||
string.appendText('foo').appendChoice(['far', 'boo']).appendText('bar');
|
||||
assert.equal(string.value, 'foo${1|far,boo|}bar');
|
||||
|
||||
string = new types.SnippetString();
|
||||
string.appendText('foo').appendChoice(['far', '$boo']).appendText('bar');
|
||||
assert.equal(string.value, 'foo${1|far,\\$boo|}bar');
|
||||
|
||||
string = new types.SnippetString();
|
||||
string.appendText('foo').appendPlaceholder('farboo').appendChoice(['far', 'boo']).appendText('bar');
|
||||
assert.equal(string.value, 'foo${1:farboo}${2|far,boo|}bar');
|
||||
});
|
||||
|
||||
test('instanceof doesn\'t work for FileSystemError #49386', function () {
|
||||
|
|
Loading…
Reference in a new issue