API: allow an extension to change the environment variables
See original GitHub issueI’m currently investigating options to simplify the usage of vcpkg artifacts in VS Code. While the example below is specific to vcpkg, similar workflows exist in other languages, like Python’s virtual environments.
- The user has a
vcpkg-configuration.json
file checked into their repository that describes the artifacts required by the project. In an embedded development context, this is typically things like ARM compiler toolchains, on-chip debuggers, and associated utilities like serial monitors. - From a shell, the user runs
vcpkg activate
. This downloads the artifacts as needed and then changes thePATH
environment variable in the current shell session to include the artifacts. Other environment variables likeCC
orCXX
may also be set depending on the artifact. - From the same shell session, the user runs
code .
to launch VS Code in the vcpkg environment.
What I’d like to do is create a VS Code extension that can run the activation steps without requiring the user to manually use a shell. Assuming the extension has a way to retrieve the desired environment variables from vcpkg, I need a way to apply these environment variables to the current VS Code instance. The simplest way I can think of to achieve this by adding a new built-in command that accepts a set of environment variables, then restarts the current VS Code process with the environment variables applied to the new process.
- Does this sound like the right approach to solving this problem? I’m willing to create the PR if the approach is sound.
- Would it be better to restart the entire process, or instead take the more limited approach of the existing “Developer: Reload Window” command which restarts most child processes but leaves the main VS Code process intact?
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:18 (12 by maintainers)
Top GitHub Comments
@Strum355 thanks for those pointers!
@bpasero @Tyriar @alexdima looks like there are at least three groups (vcpkg, nix, and direnv) interested in an API for extensions to set environment variables. Is that sufficient to restart the discussion we paused earlier about adding the proposed
extHostEnvironment
VS Code API? Rereading the earlier discussion, the remaining open issues are lifecycle concerns around reading persisted environment variable state before launching the extension host process, and formal review of the UI changes.If this seems like enough community interest, just let me know what next steps I should take (e.g. schedule a meeting, open a PR, continue discussion here, etc.).
cc @qarni
Unless Im misunderstanding, theres a lot of interest outside of vcpkg and nix, including the direnv community. See:
and some other issues I’m not going to dig through my browser history for.
The proposed API changes of yours above looked promising, so its a bit disappointing to see its progress paused in favour of vcpkg specific solutions 😕 Is there a process for getting momentum again?