Skip to content

Commit cd262f3

Browse files
author
Greg Van Liew
authored
Merge branch 'master' into settingsComments
2 parents 93e87ca + 0a0f2bf commit cd262f3

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/vs/vscode.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,17 @@ declare module 'vscode' {
29672967
*/
29682968
appendPlaceholder(value: string | ((snippet: SnippetString) => any), number?: number): SnippetString;
29692969

2970+
/**
2971+
* Builder-function that appends a choice (`${1|a,b,c}`) to
2972+
* the [`value`](#SnippetString.value) of this snippet string.
2973+
*
2974+
* @param values The values for choices - the array of strings
2975+
* @param number The number of this tabstop, defaults to an auto-increment
2976+
* value starting at 1.
2977+
* @return This snippet string.
2978+
*/
2979+
appendChoice(values: string[], number?: number): SnippetString;
2980+
29702981
/**
29712982
* Builder-function that appends a variable (`${VAR}`) to
29722983
* the [`value`](#SnippetString.value) of this snippet string.

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,18 @@ export class SnippetString {
740740
return this;
741741
}
742742

743+
appendChoice(values: string[], number: number = this._tabstop++): SnippetString {
744+
const value = SnippetString._escape(values.toString());
745+
746+
this.value += '${';
747+
this.value += number;
748+
this.value += '|';
749+
this.value += value;
750+
this.value += '|}';
751+
752+
return this;
753+
}
754+
743755
appendVariable(name: string, defaultValue?: string | ((snippet: SnippetString) => any)): SnippetString {
744756

745757
if (typeof defaultValue === 'function') {

src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,25 @@ suite('ExtHostTypes', function () {
527527
string.appendVariable('BAR', b => { });
528528
assert.equal(string.value, '${BAR}');
529529

530+
string = new types.SnippetString();
531+
string.appendChoice(['b', 'a', 'r']);
532+
assert.equal(string.value, '${1|b,a,r|}');
533+
534+
string = new types.SnippetString();
535+
string.appendChoice(['b', 'a', 'r'], 0);
536+
assert.equal(string.value, '${0|b,a,r|}');
537+
538+
string = new types.SnippetString();
539+
string.appendText('foo').appendChoice(['far', 'boo']).appendText('bar');
540+
assert.equal(string.value, 'foo${1|far,boo|}bar');
541+
542+
string = new types.SnippetString();
543+
string.appendText('foo').appendChoice(['far', '$boo']).appendText('bar');
544+
assert.equal(string.value, 'foo${1|far,\\$boo|}bar');
545+
546+
string = new types.SnippetString();
547+
string.appendText('foo').appendPlaceholder('farboo').appendChoice(['far', 'boo']).appendText('bar');
548+
assert.equal(string.value, 'foo${1:farboo}${2|far,boo|}bar');
530549
});
531550

532551
test('instanceof doesn\'t work for FileSystemError #49386', function () {

0 commit comments

Comments
 (0)