mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
add variable-builder methods to snippet string, #4956
This commit is contained in:
@@ -561,6 +561,31 @@ export class SnippetString {
|
||||
this.value += value;
|
||||
this.value += '}';
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
appendVariable(name: string, defaultValue?: string | ((snippet: SnippetString) => any)): SnippetString {
|
||||
|
||||
if (typeof defaultValue === 'function') {
|
||||
const nested = new SnippetString();
|
||||
nested._tabstop = this._tabstop;
|
||||
defaultValue(nested);
|
||||
this._tabstop = nested._tabstop;
|
||||
defaultValue = nested.value;
|
||||
|
||||
} else if (typeof defaultValue === 'string') {
|
||||
defaultValue = defaultValue.replace(/\$|}/g, '\\$&');
|
||||
}
|
||||
|
||||
this.value += '${';
|
||||
this.value += name;
|
||||
if (defaultValue) {
|
||||
this.value += ':';
|
||||
this.value += defaultValue;
|
||||
}
|
||||
this.value += '}';
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user