microsoft / vscode

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

Prepending using shell integration does not work for zsh, even when shell integration is activated #205133

Closed karrtikr closed 7 months ago

karrtikr commented 8 months ago

Does this issue occur when all extensions are disabled?: Yes/No

Extension version: 2024.1.10391007 VS Code version: Code 1.86.0 (05047486b6df5eb8d44b2ecd70ea3bdf775fd937, 2024-01-31T10:27:46.147Z)

Opening on behalf of @JoelFeiner-viimed: https://github.com/microsoft/vscode-python/issues/22881, and @matt-hires: https://github.com/microsoft/vscode-python/issues/22899

Steps to Reproduce:

  1. Prepending environment variable PATH in environment collection with /home/joel/.vscode/extensions/ms-python.python-2024.1.10441459/pythonFiles/deactivate/zsh:/home/joel/.local/share/virtualenvs/edge-49eYqZTG/bin: using options: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}

  2. Value of PATH in zsh, notice how /home/joel/.vscode/extensions/ms-python.python-2024.1.10441459/pythonFiles/deactivate/zsh:/home/joel/.local/share/virtualenvs/edge-49eYqZTG/bin: appears exactly once despite prepending it twice

  3. Prepending environment variable PATH in environment collection with the same value using options: {"applyAtShellIntegration":true,"applyAtProcessCreation":false}

  4. Value of PATH in zsh

/home/joel/.pyenv/shims:/home/joel/bin:/home/joel/pycharm/bin:/home/joel/.nvm/versions/node/v16.20.0/bin:/home/joel/.pyenv/bin:/home/joel/bin:/home/joel/pycharm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

Notice how the value is not prepended, both of them which suggests that automatic shell integration fails to prepend to PATH.

Relevant details:

.zshrc

``` export PATH="$HOME/bin:$HOME/pycharm/bin:$PATH" export PAGER="less" export LESS="$LESS -FRXK" #export LESS="-iMSx4 -FX" export PYENV_ROOT="$HOME/.pyenv" command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion setopt nointeractivecomments setopt nosharehistory unsetopt sharehistory # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh ```

Shell integration is activated according to screenshot:

image

vscodenpa commented 8 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.86.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

karrtikr commented 8 months ago

Btw, both 633 and 133 shell integration sequences were not reported via the terminal data write event, so automatic shell integration may not be working, despite saying it's activated?

norambna commented 8 months ago

automatic shell integration may not be working, despite saying it's activated?

Yes, exactly this is happening on my system!

Version: 1.86.1
Commit: 31c37ee8f63491495ac49e43b8544550fbae4533
Date: 2024-02-07T09:07:19.849Z
Electron: 27.2.3
ElectronBuildId: 26495564
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Linux x64 6.5.13-7-MANJARO
meganrogge commented 7 months ago

Since shell integration is getting activated, but the sequences are not coming through, the only thing I can imagine is that somewhere within our script, there's an error getting thrown so it exits before our sequences are put into place.

I see that you have powerlevel 10k sourced within your .zshrc. does commenting out these lines fix it?

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
meganrogge commented 7 months ago

@Tyriar reminded me that powerlevel 10k will disable our shell integration script from running by design as there were problems with the interplay of that and our shell integration.

Tyriar commented 7 months ago

We should be good to move the env stuff above the p10k exit to fix this problem:

https://github.com/microsoft/vscode/blob/e4a37b21c72e8d78795803a4d1fcf714cc7aa9bd/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh#L35-L39

meganrogge commented 6 months ago

Verified via code review