Avoid unexpected value changes

This commit is contained in:
okmttdhr 2019-11-09 21:12:44 +09:00
parent 6378c89efd
commit 92b36ffc78
2 changed files with 21 additions and 3 deletions

View file

@ -740,9 +740,15 @@ export class SnippetString {
return this;
}
appendChoice(values: string[], number?: number): SnippetString {
this.appendPlaceholder(values.toString(), number);
this.value = this.value.replace(/:/g, '|').replace(/}/g, '|}');
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;
}

View file

@ -534,6 +534,18 @@ suite('ExtHostTypes', function () {
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 () {