microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.7k stars 28.7k forks source link

PATH mutation using EnvironmentVariableCollection prepend is overwritten in zsh #188235

Open hyangah opened 1 year ago

hyangah commented 1 year ago

VS Code Go extension tries to change the integrated terminals' PATH environment variable using EnvironmentVariableCollection.prepend api.

I verified that the change contribution is known to vscode using "Terminal: Show Environment Contributions" command.

# Terminal Environment Changes

## Extension: golang.go

- `PATH=/Users/hakim/sdk/go1.20.3/bin:${env:PATH}`

## Extension: vscode.git

- `GIT_ASKPASS=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh`
...

When I create a terminal tab with bash, I see the PATH change applied and go sdk path prepended as expected.

But, when I create a terminal with zsh, it looks like zsh prepends the login shell PATH again after applying our extension's PATH change.

Note all "terminal.integrated.profiles.*" settings were default.

A workaround I found is to remove "-l" arg from the default "terminal.integrated.profiles.osx.zsh" setting. But I don't know if it's ok to recommend this change to all zsh users. I see the default "terminal.integrated.profiles.osx.bash" also has "-l" but this bad interaction doesn't happen. Is it a known issue, or it is WAI?

Tyriar commented 1 year ago

This is because login shells on macOS completely reset the environment. We have a proposal coming that will let you work around this by setting it via shell integration which runs after the login init scripts https://github.com/microsoft/vscode/issues/179476

lowang-bh commented 1 year ago

removing "-l" arg from the default "terminal.integrated.profiles.osx.zsh" setting does not work for me.

image
Tyriar commented 1 year ago

Actually this was meant to be fixed by https://github.com/microsoft/vscode/issues/99878. The fix will oly work if you have shell integration enabled. Do you see these dots to the left of the terminal?

image

uruemu commented 1 year ago

@Tyriar I see those dots and seem to have shell integration enabled but still have the same issue. I am also using go version manager gvm

Screenshot 2023-08-31 at 7 57 07 AM
wulling1024 commented 11 months ago

hi @Tyriar any update? I also encountered the same problem. Go env cannot be activated when using zsh. cc: @hyangah

pedronasser commented 9 months ago

Cool. Time to downgrade VSCode again...

NeonWizard commented 9 months ago

Same issue here, shouldn't this be prioritized? This is heavily affecting the development process at my company and I'm sure a lot of other people

glebarez commented 7 months ago

this is the second time i come across this bug. the suggested "remove -l for zsh" doesn't work this time. What helped:

WARNING: this is VSCode factory reset https://stackoverflow.com/a/64518036/11362891

vishalwadhwa13 commented 1 week ago

Hi team, facing the same issue. Any alternate solutions?

coderbean commented 1 week ago

same issue, changed to bash to avoid it