diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 39d770789fa..e5cc9774725 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -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. diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 71bbf302eeb..e49a9190983 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -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') { diff --git a/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts b/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts index f33a4d5f6e6..e372fcffa8d 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts @@ -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 () {