Reputation: 3193
I know there is ${workspaceRoot}
environment variable available. What other environment variables are there to use?
One that would be of particular interest would be the filename without the ${workspaceRoot}
part with all \
chars replaced with /
so we can use this as a url builder. Then you could use a URL like "http://localhost:9876/${relativeFile}
".
It would be really helpful if there is something like a ${relativeFile}
and a ${relativeFolder}
.
Upvotes: 33
Views: 66062
Reputation: 2062
You can find a list of available substitution variables here:
https://code.visualstudio.com/docs/editor/tasks#_variable-substitution
Edit: The full list can actually be found in the variableResolver.ts source file. The base class defines a resolve()
method that uses a regular expression to replace matches with string property values with the same name. Notice that SystemVariables
also includes all process.env
values, where the pattern is to use a colon ${env:KEY}
.
Upvotes: 7
Reputation: 1909
Be aware the ${workspaceRoot}
variable has been deprecated in favor of the ${workspaceFolder}
variable. It was deprecated (and no longer documented) in order to align better with Multi-root workspace support.
You can find the list at this link: https://code.visualstudio.com/docs/editor/variables-reference
For posterity reasons I'm going to list the variables (I've been trying to find them as well today), copying right from the link (and prettifying it), in case it ever changes again:
Visual Studio Code supports variable substitution in Debugging and Task configuration files. Variable substitution is supported inside strings in launch.json and tasks.json files using ${variableName}
syntax.
The following predefined variables are supported:
Note: The ${workspaceRoot}
variable is deprecated in favor of the ${workspaceFolder}
variable.
You can also reference environment variables through ${env:Name}
syntax (for example, ${env:PATH}
)
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js",
"cwd": "${workspaceFolder}",
"args": [ "${env:USERNAME}" ]
}
Note: Be sure to match the environment variable name's casing, for example ${env:Path}
on Windows.
You can reference VS Code settings and commands using the following syntax:
${config:Name}
- example: ${config:editor.fontSize}${command:CommandID}
- example: ${command:explorer.newFolder}By appending the root folder's name to a variable (separated by a colon), it is possible to reach into sibling root folders of a workspace. Without the root folder name, the variable is scoped to the same folder where it is used.
For example, in a multi root workspace with folders Server and Client, a ${workspaceFolder:Client}
refers to the path of the Client root.
Upvotes: 49