-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support per-window variable environments #15452
Comments
Since I can't reproduce the problems you raise in steps 6 and 12, I'll close this issue. Please see my screencast recorded just now on the latest Insiders build: https://www.youtube.com/watch?v=3WvA-mK6xu0 I believe you can reproduce it on your machine, though, so let's try to find out why that happens. What do you get when running PS: I found it tough to understand what your problem is, given the verbosity of your prose. Thanks for the Steps to Reproduce section, it would've been hard otherwise. When filing future issues, please try to keep it short and simple. PPS: You forgot to rename Atom to VS Code in one instance, during your copy paste. |
Here's a screencast reproducing the issue. Notice that there are three separate runs of VS Code, between which I entirely quit the application:
In each of those runs, I open the Please note that when I say "all is fine" for the first run, obviously this is WRT the Here's the output you asked for:
PS: sorry for the verbosity. I'll keep things short in the future. PPS: nice catch, well played ;-) |
To fix the environment of the second window in your second run, we could have every window created from the UI have a clean environment too, instead of inheriting the one from spawn time. But then, we'd just have other users complaining that this wasn't expected behaviour and that they expect the initial environment to propagate to all windows. There are different ways to approach this problem. This is the set of rules we've decided to go with:
We believe this set of rules makes most users happy and not weary of unexpected behaviour. |
Untrue, or at least ambiguous. The following is currently correct:
This is IMHO the pain point: to me only the window that pertains to the path passed to
So there are two opposing use cases here. Could it be made into a setting? That'd be awesome as I'd love to have control over this so that Also, there are a couple corner cases. What's the behaviour you expect to have upon:
AFAICT both may make the user lose its env if it was spawned from the command line. |
Yes, that disambiguation was necessary. 👍 Don't you think it would be wrong, or at the very least confusing, to spawn Code with None of the two corner cases will preserve the environment. |
Not confusing at all for me, as this does what I expect from a multiwindow document-based app on macOS:
This becomes increasingly important as you start to develop within different Go workspaces, across varying tech stacks, and using various env vars that are tied to each project (for, say, Docker, rake, or rbenv) that you don't want to leak from one repo/project/workspace to another. This behaviour integrates naturally with the platform conventions as well as making it easy to support OS features such as proper state restoration (possibly serializing the env to be restored upon restart/after update?). This is tangential to this issue but I'd love to be able to hit "yes, restart and update right now!" on a new release notification and have things continue to work, as well as the editor surviving logouts/reboots, but that depends the extend of which you want to push blending with the platform expectations. A quick informal poll shows that coworkers around me that use macOS seem to generally agree with this behaviour. As a general rule, the ones that "get" the behaviour you expect come from a Linux background yet accept it as a glitch they have to work around. As a rule of thumb people over here generally prefer having a warning that |
You've at least convinced me to seriously consider making a change. Good job! 👍 |
Awesome! Thanks to you for having kept on lending an ear :-) |
Running into issue that may be related. Custom Task to run Code's terminal windows open with the correct context, but not tasks. Is there a way around this? |
@pelted Interesting, I'll take that into account when I'm diving into the code (which happens with great irregularity but this issue is still on my radar!) |
For those who are still waiting for a workaround, I made a script that wraps around This script makes sure that opening a folder using Place this script somewhere such that it has higher Btw: If you don't need #!/bin/bash
open -b com.microsoft.VSCode "$@" But then you don't get 100% feature parity with |
FWIW @joaomoreno @Tyriar this is ultimately what I'm getting at with #56125 - PATH specifically changing is of course a problem for me, but I hadn't even realized the extent of my "problem," w.r.t. environments getting inherited on subsequent launches. For instance,
(terminal 2)
not only results in two Code windows with non-useful PATHs, but also a weird chimera environment in the second window with env variables from both my_env_2 and my_env_1, which isn't something I'd even realized before. |
@alexwhittemore So... what's your expected behavior? |
As a simple test, open two terminals: in term 1:
In a Code terminal we see
of course. Moving over to a second terminal:
And in Code:
In this second case, TESTVAR and VIRTUAL_ENV are correct, but I'd expect UNIQUE to be unset. This can lead to oddities where launching subsequent windows results in having partial environments from previous windows. In my use case, the hangup is, if I launch Code inside a virtualenv, subsequent windows not-necessarily-launched-from-a-virtualenv will adopt that virtualenv. And anyway, the behavior is inconsistent depending on order-of-window-launched, which seems undesirable per se. |
Note #55194 which fixes one of the issues with this. But there may be more. VS Code seems to already have the basic infrastructure for this in-place, I think it's just a matter of fixing cases where it's not working, and ironing out it's behavior. |
Thanks for the info! |
@lloeki We started working on this and coming up with a better strategy over here: #108804 (comment) I believe today some of the inconsistencies you mention are already fixed. Namely step (6) on the initial steps is no longer true: it works today. Will close this issue and move the work over to #108804 |
Problem
Various tools don't operate correctly depending on the order and the manner with which VSCode is started on macOS.
Also, persisted state is not restored consistently.
Note: the problem is similar to atom/atom#4126. Although I feel dirty pointing you to a thread pertaining to That Other Editor, the issue is largely the same and some discussion happened over there that one may want to look into for the full effect.
Cause
Depending the manner in which VSCode is started, a different environment is inherited.
code
in the terminal: inherits currently set varsThis applied to when the app is started, not when a new window is opened, in which case that window will inherit the current process env (which is normal OS X behaviour).
Current workaround / Anti-feature
Manually control Code startup each time you want to use it in a specific environment.
Why is it an anti feature? If you want two projects open at the same time but with different environments, you're busted.
Also, long running sessions and "wait what env was that started with already?" (session can also mean the idiomatic "document != app" macOS way: "Visual Studio Code.app is started but no windows are opened").
Also also, frustration quickly sets in when you start it up the wrong way and have to quit and restart halfway through your work and notice your linter does not actually run (manual config does not cut it because 1. it's manual and 2. constantly changing versions means constantly changing path).
Possible solution
.git
,Gemfile
,.rubocop.yml
,.gopath
, which they have to do anyway else at least starting via launchd is broken, if not more), not to manual handling by developer.Consequences
PATH
& al. is properly set and tools like linters can leverage the env to use chruby/rbenv/whatever.open -a "Visual Studio Code"
and usingcode foo
on the terminal are all consistent, whatever the order they are executed in.Additional note
On another planet, I don't know if this issue applies to other OSes as well besides macOS. Everything depends on how process management and app/doc/task GUI model is expected to be handled there.
Final word
All of this really matters daily when you juggle between projects and makes VSCode feel like a brittle product, making angry coworkers throwing rusted nails at me for having pushed VSCode on them. (I realise I pushed the same argument forward on the Atom issue, but hey, we all know deep inside that VSCode is OvbiouslyBetter™, and being thrown sharp objects at twice is doubleplus unfun).
Details
Steps to Reproduce:
process.env
in JS consoleexport FOO=bar
code somewhere
or whateverprocess.env
in console, notice there's noFOO
code somewhere
or whateverprocess.env
in console, notice there'sFOO
process.env
in console, notice there'sFOO
FOO
)code somewhereelse
or whateverprocess.env
in console, notice there'sFOO
The text was updated successfully, but these errors were encountered: