question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API: allow an extension to change the environment variables

See original GitHub issue

I’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.

  1. 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.
  2. From a shell, the user runs vcpkg activate. This downloads the artifacts as needed and then changes the PATH environment variable in the current shell session to include the artifacts. Other environment variables like CC or CXX may also be set depending on the artifact.
  3. 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:open
  • Created a year ago
  • Reactions:3
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
benmcmorrancommented, Nov 21, 2022

@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

3reactions
Strum355commented, Nov 19, 2022

If there’s enough community interest, I’m sure we could restart discussions about a VS Code API. Right now it sounds like it’s just vcpkg and nix.

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment Variable APIs - IBM
Qp0zPutEnv() (Change or add environment variable (extended)) is an IBM i extension to the standard putenv() function. Qp0zPutSysEnv() (Change or add a system- ......
Read more >
Lambda Extensions API - AWS Documentation
Environment variables : Extensions can access the function's environment variables, except for the following variables that are specific to the runtime process: ...
Read more >
Environment variables and app settings in Azure App Service
Set to 0 to disable the use of private site extensions. WEBSITE_TIME_ZONE, By default, the time zone for the app is always UTC....
Read more >
Environment Variables - Mesa 3D
If this environment variable is set, application calls to wglSwapIntervalEXT() will have no effect. VA-API environment variables¶. VAAPI_MPEG4_ENABLED¶. enable ...
Read more >
Basic Features: Environment Variables - Next.js
js environment automatically, allowing you to use it anywhere in your code. The value will be inlined into JavaScript sent to the browser...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found