// try to separate variable arguments from variable name
letargument:string|undefined;
constparts=variable.split(':');
if(parts.length>1){
variable=parts[0];
argument=parts[1];
}
// common error handling for all variables that require an open editor
constgetFilePath=():string=>{
constfilePath=this._context.getFilePath();
if(filePath){
returnfilePath;
}
thrownewError(localize('canNotResolveFile',"'{0}' can not be resolved. Please open an editor.",match));
};
// common error handling for all variables that require an open folder and accept a folder name argument
constgetFolderUri=():uri=>{
if(argument){
constfolder=this._context.getFolderUri(argument);
if(folder){
returnfolder;
}
thrownewError(localize('canNotFindFolder',"'{0}' can not be resolved. No such folder '{1}'.",match,argument));
}
if(folderUri0){
returnfolderUri0;
}
if(this._context.getWorkspaceFolderCount()>1){
thrownewError(localize('canNotResolveWorkspaceFolderMultiRoot',"'{0}' can not be resolved in a multi folder workspace. Scope this variable using ':' and a workspace folder name.",match));
}
thrownewError(localize('canNotResolveWorkspaceFolder',"'{0}' can not be resolved. Please open a folder.",match));
};
switch(variable){
case'env':
if(argument){
if(isWindows){
argument=argument.toLowerCase();
}
thrownewError(localize('missingConfigName',"'{0}' can not be resolved because no settings name is given.",match));
// common error handling for all variables that require an open folder and accept a folder name argument
switch(variable){
case'workspaceRoot':
case'workspaceFolder':
case'workspaceRootFolderName':
case'workspaceFolderBasename':
case'relativeFile':
if(argument){
constfolder=this._context.getFolderUri(argument);
if(folder){
folderUri=folder;
}else{
thrownewError(localize('canNotFindFolder',"'{0}' can not be resolved. No such folder '{1}'.",match,argument));
}
}
if(!folderUri){
if(this._context.getWorkspaceFolderCount()>1){
thrownewError(localize('canNotResolveWorkspaceFolderMultiRoot',"'{0}' can not be resolved in a multi folder workspace. Scope this variable using ':' and a workspace folder name.",match));
}
thrownewError(localize('canNotResolveWorkspaceFolder',"'{0}' can not be resolved. Please open a folder.",match));
}
break;
default:
break;
constenv=this._envVariables[argument];
if(types.isString(env)){
returnenv;
}
// For `env` we should do the same as a normal shell does - evaluates missing envs to an empty string #46436
return'';
}
thrownewError(localize('missingEnvVarName',"'{0}' can not be resolved because no environment variable name is given.",match));
// common error handling for all variables that require an open file
switch(variable){
case'file':
case'relativeFile':
case'fileDirname':
case'fileExtname':
case'fileBasename':
case'fileBasenameNoExtension':
if(!filePath){
thrownewError(localize('canNotResolveFile',"'{0}' can not be resolved. Please open an editor.",match));