vscode: Prepending PATH env var with environmentVariableCollection doesn't work on macOS
This was covered a little bit in https://github.com/microsoft/vscode/issues/94153 but that issue is locked and can’t be discussed there. This feature feels pretty broken on macOS and I hope might be revisited.
The issue is on macOS prepending to PATH:
context.environmentVariableCollection.prepend("PATH", "/foo/my/path:");
This ends up being added to the end of the path, rather than the start. @Tyriar wrote up why this is in microsoft/vscode-docs@38653d4 and offered two workarounds, however neither of them are usable in my testing (as well as not really being feasible to tell all users to change):
"terminal.integrated.inheritEnv": falsemakes no difference at all, the PATH till is added to the end (this is a problem because the purpose of usingprependabove is that we need to override any existing SDK on PATH with the one the user just selected)"terminal.integrated.shellArgs": []results in a completely emptyPATHbesides the values I’ve prepended, which means that pretty much everything else is missing and won’t work. This might be solvable by pushingprocess.env.PATHintoenvironmentVariableCollectiontoo, however the prompt to the user would look ridiculous as it would include their entire PATH
I appreciate this probably isn’t VS Code’s fault, but given macOS is fairly common and this behaviour seems to happen on a clean macOS install (it happens on both of mine, and I’ve customised almost nothing) it feels like it’s worth trying to fix (maybe even if it means sending export PATH=foo:$PATH once the shell is initialised? 😄).
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 25
- Comments: 19 (15 by maintainers)
Commits related to this issue
- Push SDK paths onto Terminal environment PATH Fixes #2209, but currently a bit doesn't currently work well because of https://github.com/microsoft/vscode/issues/99878. — committed to Dart-Code/Dart-Code by DanTup 4 years ago
- Push SDK paths onto Terminal environment PATH Fixes #2209, but doesn't currently work well because of https://github.com/microsoft/vscode/issues/99878. — committed to Dart-Code/Dart-Code by DanTup 4 years ago
- src/goEnvironmentStatus.ts: use the new EnvironmentVariableCollection API vscode.ExtensionContext.EnvironmentVariableCollection is available since 1.46 (May 2020 release https://code.visualstudio.com... — committed to hyangah/vscode-go by hyangah 4 years ago
- src/goEnvironmentStatus.ts: use the new EnvironmentVariableCollection API vscode.ExtensionContext.EnvironmentVariableCollection is available since 1.46 (May 2020 release https://code.visualstudio.com... — committed to golang/vscode-go by hyangah 4 years ago
- src/goEnvironmentStatus: fix PATH mutation logic in osx I misuderstood the comment in https://github.com/microsoft/vscode/issues/99878#issuecomment-642808852 which resulted in that the PATH change do... — committed to golang/vscode-go by hyangah 4 years ago
- Work in progress for PATH prefix/suffix in si Part of #99878 — committed to microsoft/vscode by Tyriar a year ago
@DanTup we’re going to remove the white one in https://github.com/microsoft/vscode/issues/151160 in favor of the “tab status”. Created https://github.com/microsoft/vscode/issues/171498 to fix the info not showing up in the “single tab”
@Tyriar thanks! This seems to work. However, the UI when changing it doesn’t seem very clear:
There’s a yellow warning triangle here, but hovering over it or clicking on it gives no indication of the problem. There’s another white warning triangle on the side, but the hover for it doesn’t appear for quite a long time after you hover over it. I don’t think it’s very discoverable if a user has an existing session and this changes (and this is made worse by the terminal seeming to persist across reloads).
Is there anything that can be done to improve this? (I can file a new issue about it if necessary).
Awesome, thanks! I’m definitely interested in testing this if/when there’s something more concrete 😃
@DanTup actually had a discussion with the Python team around this so I’m guessing this will get prioritized soon. The way I’m envisioning this working is for some environment variable being set (VSCODE_ENV_CONTRIBUTION or something?) and the shell integration script checking that and re-applying it after the init scripts run