Skip to content
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

vscode-neovim doesn't work with Elvish as default shell #1804

Closed
1 task done
tmpm697 opened this issue May 4, 2024 · 15 comments
Closed
1 task done

vscode-neovim doesn't work with Elvish as default shell #1804

tmpm697 opened this issue May 4, 2024 · 15 comments

Comments

@tmpm697
Copy link

tmpm697 commented May 4, 2024

What happened, and what did you expect to happen?

I have this script in PATH variable and used for vscode to spawn neovim instance to use with vscode-neovim extension:

#!/usr/bin/env bash
NVIM_APPNAME=vscode-neovim nvim "$@"

but it fail to start (my current default shell is elvish)
Screenshot 2024-05-04 at 5 42 55 PM

before switched to elvish, i use zsh and the above script just work out-of-box

Output of "elvish -version"

0.20.1

Code of Conduct

@xiaq
Copy link
Member

xiaq commented May 4, 2024

Elvish is not responsible for interpreting the shebang line, so there's something else going on.

How did you set Elvish to be your default shell?

@xiaq
Copy link
Member

xiaq commented May 4, 2024

Also - what's the name of your script and can you elaborate why it's necessary for your setup?

I took a look at the vscode-neovim extension and it doesn't mention that you need to create a custom script to use it, so I suppose it's some custom setup you're using?

@xiaq xiaq changed the title Elvish does not respect /usr/bin/env? vscode-neovim doesn't work with Elvish as default shell May 4, 2024
@tmpm697
Copy link
Author

tmpm697 commented May 4, 2024

Elvish is not responsible for interpreting the shebang line, so there's something else going on.

How did you set Elvish to be your default shell?

I set default shell by issue this command: sudo chsh -s $(which elvish) $USER
note that i use macos sonoma and nix to install elvish.

which elvish resolve to smth like /Users/user/.nix-profile/bin/elvish but this should not be any problem, just to verbose
more.

I did re-login/out before doing any test.

Also - what's the name of your script and can you elaborate why it's necessary for your setup?

it's named vscode-neovim.sh as in the image.

I took a look at the vscode-neovim extension and it doesn't mention that you need to create a custom script to use it, so I suppose it's some custom setup you're using?

you can check it here: https://github.com/milanglacier/nvim#seamless-integration-with-vscode

this script due to users want to use a separate neovim config for vscode-neovim instance and the default neovim that load ~/.config/nvim

so i have another folder ~/.config/vscode-neovim that store neovim config for neovim instance of vscode-neovim.

@xiaq
Copy link
Member

xiaq commented May 4, 2024

OK thanks, I understand what you are trying to do now.

There seems to be quite a few moving parts in this setup you are using, and any component could be passing code through the login shell (rather than the correct thing, using an API that maps to a direct exec call without going through the shell), so making sure that the vscode-neovim script is using bash may not be sufficient, as is apparently the case here...

@xiaq
Copy link
Member

xiaq commented May 4, 2024

Some things to check:

  • Does your setup work correctly if you change your login shell back to bash or zsh?
  • Did you try the alternative approach of separating the config directory (setting vscode-neovim.NVIM_APPNAME)?

@xiaq
Copy link
Member

xiaq commented May 4, 2024

Hmm looking at the error code you're getting (ENOENT) - did you set vscode-neovim.neovimExecutablePaths.darwin to the full absolute path of your script?

@krader1961
Copy link
Contributor

before switched to elvish, i use zsh and the above script just work out-of-box

Note that Zsh and Bash are both POSIX compatible shells (more or less). I would expect that you would experience similar problems if you used another non-POSIX shell such as Fish or Xonsh. This type of situation is why the best practice is to leave your "login" shell something like Zsh or Bash and configure your terminal emulator to spawn Elvish instead of your login shell; see https://elv.sh/get/default-shell.html. As @hanche suggested in the IM chat it a useful experiment is to try invoking the relevant programs with something like export SHELL=/bin/bash to ensure the default shell for Vscode or the Nvim plugin is POSIX compatible.

My primary OS is also macOS and it is very frustrating that it doesn't support a usable strace or truss command. It's dtruss and dtrace tools are useful but not for situations like this. What I typically do is create a "wrapper" script that looks something like this to capture the arguments to a program:

#!/bin/sh
echo "$@" > /tmp/$$.args
exec /path/to/real-program "$@"

Where the original program is renamed to /path/to/real-program and the script is installed as the original /path/to/program whose invocation we want to track.

@tmpm697
Copy link
Author

tmpm697 commented May 5, 2024

Some things to check:

  • Does your setup work correctly if you change your login shell back to bash or zsh?
  • Did you try the alternative approach of separating the config directory (setting vscode-neovim.NVIM_APPNAME)?

yes, default shell is zsh which work out-of-box
I don't have another approach to this.

vscode-neovim.neovimExecutablePaths.darwin

this set to vscode-neovim.sh and it's avail when typing in terminal --> vscode-neovim.sh is avail in PATH for use. (with elvish as default shell)

@tmpm697
Copy link
Author

tmpm697 commented May 5, 2024

before switched to elvish, i use zsh and the above script just work out-of-box

Note that Zsh and Bash are both POSIX compatible shells (more or less). I would expect that you would experience similar problems if you used another non-POSIX shell such as Fish or Xonsh. This type of situation is why the best practice is to leave your "login" shell something like Zsh or Bash and configure your terminal emulator to spawn Elvish instead of your login shell; see https://elv.sh/get/default-shell.html. As @hanche suggested in the IM chat it a useful experiment is to try invoking the relevant programs with something like export SHELL=/bin/bash to ensure the default shell for Vscode or the Nvim plugin is POSIX compatible.

My primary OS is also macOS and it is very frustrating that it doesn't support a usable strace or truss command. It's dtruss and dtrace tools are useful but not for situations like this. What I typically do is create a "wrapper" script that looks something like this to capture the arguments to a program:

#!/bin/sh
echo "$@" > /tmp/$$.args
exec /path/to/real-program "$@"

Where the original program is renamed to /path/to/real-program and the script is installed as the original /path/to/program whose invocation we want to track.

this can be more useful than force macos user default shell but when i try to set vscode's terminal default shell, i can't:
Screenshot 2024-05-05 at 12 10 34 PM
"terminal.integrated.shell.osx": is hidden and not seem to work. is there a way to change vscode's default shell?

@tmpm697
Copy link
Author

tmpm697 commented May 5, 2024

ok i got that, it's smth like "terminal.integrated.defaultProfile.osx": "elvish",

@tmpm697 tmpm697 closed this as completed May 5, 2024
@xiaq
Copy link
Member

xiaq commented May 5, 2024

@tmpm697 Glad to know you worked around the issue. I've updated https://elv.sh/get/default-shell.html to include instruction for using Elvish from VS Code's terminal and documented vscode-neovim's incompatibility issue.

@tmpm697
Copy link
Author

tmpm697 commented May 6, 2024

@tmpm697 Glad to know you worked around the issue. I've updated https://elv.sh/get/default-shell.html to include instruction for using Elvish from VS Code's terminal and documented vscode-neovim's incompatibility issue.

thanks, if having elvish shell this way, is that it will first spawn zsh and then do exec elvish?

if true, then elvish will get all exported env vars from zsh?

@krader1961
Copy link
Contributor

thanks, if having elvish shell this way, is that it will first spawn zsh and then do exec elvish?

if true, then elvish will get all exported env vars from zsh?

Yes, because that is how env vars work; at least on Unix like operating systems such as macOS and Linux. Env vars are private to each process. When a process, such as zsh, spawns a new process it normally tells the OS to pass a copy of its env vars to the new process.

@xiaq
Copy link
Member

xiaq commented May 7, 2024

@tmpm697 Glad to know you worked around the issue. I've updated https://elv.sh/get/default-shell.html to include instruction for using Elvish from VS Code's terminal and documented vscode-neovim's incompatibility issue.

thanks, if having elvish shell this way, is that it will first spawn zsh and then do exec elvish?

if true, then elvish will get all exported env vars from zsh?

I don't think any terminal has the literal behavior you're describing. Normally the login shell won't be involved. tmux is an exception - if you configured tmux to launch Elvish, you'll still get your login shell in the terminal, which will pass its environment variables to tmux and then to Elvish.

AFAICT some Linux desktop environments involve the login shell at some point during the login process, so you can end up getting environment variables from the profile file of the login shell, but you're using macOS so that's not relevant to you.

thanks, if having elvish shell this way, is that it will first spawn zsh and then do exec elvish?
if true, then elvish will get all exported env vars from zsh?

Yes, because that is how env vars work; at least on Unix like operating systems such as macOS and Linux. Env vars are private to each process. When a process, such as zsh, spawns a new process it normally tells the OS to pass a copy of its env vars to the new process.

I think you're answering @tmpm697's second question assuming that the answer to the first question is yes, which I believe is not the case.

@tmpm697
Copy link
Author

tmpm697 commented May 9, 2024

vscode's settngs:

  "terminal.integrated.defaultProfile.osx": "elvish",

no idea but this is number of vars in elvish and zsh:

new vscode terminal --> starting shell is elvish:
~/s/nix ➜ e:env | wc -l
47
~/s/nix ➜ zsh
~/s/nix ➜ env | wc -l 
47

compare zsh's env | rg test_var vs elvish's e:env | rg test_var look the same.

so it seems that vscode on macos spawn zsh first and then exec elvish that automatically import all exported vars from zsh?

I don't set-env in my elvish config, but surprisingly if u set same var in evlish via set-env, it'll overwrite exported var from zsh but seem expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants