Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Evaluate VS Code Environment Variables in Extension

I asked a similar question to this a couple weeks ago, but I think because it was so specific and lengthy, I did not get an answer. See original post. I'll try and ask a more direct question this time--

I'm currently writing a VS Code extension. Is there a function built into the VS Code API that when given a string as input, allows for evaluation of environment variables, like those used in the tasks.json file? Full list of variables can be found here: https://code.visualstudio.com/docs/editor/variables-reference.

Such a function would take in a string containing environment variables and information about the workspace, then evaluate the environment variables in it. Example: "${workspaceFolder}_${fileBasenameNoExt}.txt""myWokspaceFolderName_myFileName.txt

I know VS Code has the functionality built in (as it is used in tasks) but I don't know how they do it and/or if I am able to use that functionality without having to rebuild it for my extension. What's the best way to implement this functionality in my extension?

like image 754
Antyos Avatar asked Aug 26 '26 12:08

Antyos


1 Answers

One easy way to check a variable's runtime value is to create a VS Code task to output the variable value to the console. For example, to see the resolved value for ${workspaceFolder}, you can create and run (Terminal > Run Task) the following simple 'echo' task in tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo",
      "type": "shell",
      "command": "echo ${workspaceFolder}"
    }
  ]
}
like image 190
ATL_DEV Avatar answered Aug 28 '26 09:08

ATL_DEV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!