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

Solargraph execution is wrapped in a login shell, messing up the path #62

Closed
vitaly opened this issue Jun 13, 2021 · 5 comments
Closed

Comments

@vitaly
Copy link

vitaly commented Jun 13, 2021

Here is the story..

I tried to use bundler with coc-solargraph, but it failed to start with the following error message:

[coc.nvim] Failed to start Solargraph: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.2.17) required by your /Users/vitaly/tmp/ruby/vim/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.17`
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
        from /usr/bin/bundle:23:in `<main>'

I couldn't figure it out for a while until I noticed that the message is coming from the system ruby, while I'm using asdf version in my setup:

> which ruby
/Users/vitaly/.asdf/shims/ruby

> asdf which ruby
/Users/vitaly/.asdf/installs/ruby/2.6.0/bin/ruby

So I figured out it must be a problem with path.

so I wrote a simple bash script to print path to STDERR and set it as my solargraph.bundlerPath

#!/bin/bash

echo SOLARPATH=$PATH >&2

My shell PATH starts with /Users/vitaly/.asdf/shims:/Users/vitaly/.asdf/bin: and then the usual directories. This is standard setup by asdf.

But what I got from my "Solargraph" is this:

[coc.nvim] Failed to start Solargraph: SOLARPATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/.npm/bin:/Users/vitaly/.asdf/shims:/Users/vitaly/.asdf/bin

So it looked like something messed up the path, adding all the standard directories at the beginning.

On a whim I decideed to see if there's any kind of wrapper process, so I added pstree -p $$ >&2 to my dump script.

And this is what I ggt:

[coc.nvim] Failed to start Solargraph: SOLARPATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/.npm/bin:/Users/vitaly/bin:/Users/vitaly/.asdf/shims:/Users/vitaly/.asdf/bin
-+= 00001 root /sbin/launchd
 \-+= 21544 vitaly /usr/local/bin/tmux -u new-session -t MAIN -A -s MAIN
   \-+= 63325 vitaly -zsh
     \-+= 21310 vitaly nvim foo.rb
       \-+= 21546 vitaly /Users/vitaly/.asdf/installs/nodejs/12.18.2/bin/node --no-warnings -r /Users/vitaly/.vim/bundle/coc.nvim/bin/check.js /Users/vitaly/.vim/bundle/coc.nvim/build/index.js
         \-+- 22777 vitaly /bin/bash /Users/vitaly/tmp/ruby/vim/dump.env.sh exec solargraph socket --port 0
           |-+- 22780 vitaly /usr/local/bin/zsh -l -c cd /Users/vitaly/tmp/ruby/vim && '/Users/vitaly/tmp/ruby/vim/dump.env.sh' exec solargraph socket --port 0
           | \-+- 22787 vitaly (zsh)
           |   \--- 22789 vitaly (wc)
           \-+- 22781 vitaly pstree -p 22777
             \--- 22785 root ps -axwwo user,pid,ppid,pgid,command

My SHELL is /usr/local/bin/zsh. For some reason executiuon is being wrapped
in a login invocation (-l) of it, which, of course, resets the PATH

If I change it to export SHELL=/bin/bash, then I get this:

[coc.nvim] Failed to start Solargraph: SOLARPATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/.npm/bin:/Users/vitaly/bin:/Users/vitaly/.asdf/shims:/Users/vitaly/.asdf/bin
-+= 00001 root /sbin/launchd
 \-+= 21544 vitaly /usr/local/bin/tmux -u new-session -t MAIN -A -s MAIN
   \-+= 63325 vitaly -zsh
     \-+= 61526 vitaly nvim foo.rb
       \-+= 61749 vitaly /Users/vitaly/.asdf/installs/nodejs/12.18.2/bin/node --no-warnings -r /Users/vitaly/.vim/bundle/coc.nvim/bin/check.js /Users/vitaly/.vim/bundle/coc.nvim/build/index.js
         \-+- 62971 vitaly /bin/bash -l -c cd /Users/vitaly/tmp/ruby/vim && '/Users/vitaly/tmp/ruby/vim/dump.env.sh' exec solargraph socket --port 0
           \-+- 62974 vitaly /bin/bash /Users/vitaly/tmp/ruby/vim/dump.env.sh exec solargraph socket --port 0
             \-+- 62975 vitaly pstree -p 62974
               \--- 62976 root ps -axwwo user,pid,ppid,pgid,command

I also tried to set my script as a language server in coc. There was no problem, path was intact, and no wrapper:

SOLARPATH=/Users/vitaly/.asdf/installs/nodejs/12.18.2/bin:/Users/vitaly/.asdf/installs/nodejs/12.18.2/.npm/bin:/Users/vitaly/bin:/Users/vitaly/.asdf/shims:/Users/vitaly/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
-+= 00001 root /sbin/launchd
 \-+= 21544 vitaly /usr/local/bin/tmux -u new-session -t MAIN -A -s MAIN
   \-+= 63325 vitaly -zsh
     \-+= 37360 vitaly nvim foo.q
       \-+= 37588 vitaly /Users/vitaly/.asdf/installs/nodejs/12.18.2/bin/node --no-warnings -r /Users/vitaly/.vim/bundle/coc.nvim/bin/check.js /Users/vitaly/.vim/bundle/coc.nvim/build/index.js
         \-+- 38069 vitaly /bin/bash /Users/vitaly/tmp/ruby/vim/dump.env.sh
           \-+- 38070 vitaly pstree -p 38069
             \--- 38071 root ps -axwwo user,pid,ppid,pgid,command

I tried to look through coc-solargraph and coc.nvim sources, but I couldn't find anything..

Any ideas what might be the problem?

@chemzqm
Copy link
Member

chemzqm commented Jun 15, 2021

The server is started by https://www.npmjs.com/package/solargraph-utils module.

@chemzqm
Copy link
Member

chemzqm commented Jun 15, 2021

@yous
Copy link

yous commented Dec 17, 2021

bash -l -c '...' or zsh -l -c '...' doesn't read .bashrc or .zshrc, respectively. From man bash:

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

@am1re
Copy link

am1re commented Apr 20, 2022

Facing similar issue with homebrew on m1 mac

@yous
Copy link

yous commented Apr 21, 2022

After 5934c42, this fixes the problem:

call coc#config('solargraph.shell', $SHELL)

In my case, my $SHELL is /bin/zsh.

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

4 participants