add support for ${workspaceFolder:<folder_name>} (#2027)

This commit is contained in:
Bob Brown
2018-05-22 12:58:09 -07:00
committed by GitHub
parent 3f5b0b7220
commit 891d590562
+13 -1
View File
@@ -152,7 +152,7 @@ export function resolveVariables(input: string, additionalEnvironment: {[key: st
}
// Replace environment and configuration variables.
let regexp: RegExp = /\$\{((env|config)(.|:))?(.*?)\}/g;
let regexp: RegExp = /\$\{((env|config|workspaceFolder)(.|:))?(.*?)\}/g;
let ret: string = input.replace(regexp, (match: string, ignored1: string, varType: string, ignored2: string, name: string) => {
// Historically, if the variable didn't have anything before the "." or ":"
// it was assumed to be an environment variable
@@ -180,6 +180,18 @@ export function resolveVariables(input: string, additionalEnvironment: {[key: st
newValue = (config) ? config.toString() : undefined;
break;
}
case "workspaceFolder": {
// Only replace ${workspaceFolder:name} variables for now.
// We may consider doing replacement of ${workspaceFolder} here later, but we would have to update the language server and also
// intercept messages with paths in them and add the ${workspaceFolder} variable back in (e.g. for light bulb suggestions)
if (name && vscode.workspace && vscode.workspace.workspaceFolders) {
let folder: vscode.WorkspaceFolder = vscode.workspace.workspaceFolders.find(folder => folder.name.toLocaleLowerCase() === name.toLocaleLowerCase());
if (folder) {
newValue = folder.uri.fsPath;
}
}
break;
}
default: { assert.fail("unknown varType matched"); }
}
return (newValue) ? newValue : match;