0

I find those two method to add environment variables.

  1. add environment variables in terminal.integrated.env.osx for terminal。
  2. add environment variables in launch.json for debugging.

But no similar config options for VSCode Process。

Some plugins often need to access specific environmental variables. In this case, I can only set up an environment variables in Terminal.App, and then open through the code command.

I hope to add this environment variable in the VS Code setting file.

starball
  • 20,030
  • 7
  • 43
  • 238
tabris
  • 1

1 Answers1

0

I'm not aware of existing VS Code settings that allow you to do this. I'm not surprised, since in general, you can't change the environment of a process that has already been started. See the following on unix.stackexchange.com for more info: change environment of a running process.

I suppose this could technically be implemented: VS Code could change its executable into a wrapper program which reads the VS Code settings file(s), then execs (without forking) the actual VS Code executable with modified environment variables from the settings. Feel free to raise a feature request and see if this is actually a legitimate idea (I'm not sure). (if you do, please comment here linking to the issue ticket for posterity).

You can specify environment variables to add to the environment of a process when you start that process. See the env command.

Also related if you're using a shell like Bash:

Or, it may be acceptable to you to just modify your system environment, which applies to all processes started in the system by default. Related:

There's a slightly related feature-request about this here for the extension host process: API: allow an extension to change the environment variables #152806. See also this comment there about more broadly applying it to the "root" VS Code process, this update/summary, and this note about using process.env for the extension host.

starball
  • 20,030
  • 7
  • 43
  • 238