castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
425 stars 23 forks source link

Couldn't start client Ruby Language Server #108

Open lpender opened 5 years ago

lpender commented 5 years ago

Has anybody written a guide on how to get started with VS Code and Ruby on Rails?

I'm sure it's really easy... but I have no idea what I'm doing.

Anyway,

When I start VSCode I see the following in the bottom right corner:

image

And in the bottom tab I see the following:

[Error - 5:17:09 PM] Starting client failed
/usr/local/Cellar/ruby/2.3.1/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem bundler (>= 0) (Gem::GemNotFoundException)
    from .git/safe/../../bin/bundle:3:in `<main>'

Some more context:

image

All I'm looking for is some documentation explaining how things work... i.e. :

I really just have no idea what's going on. Is there something I can read ?

Thanks!

castwide commented 5 years ago

First, try running solargraph -v from the command line to make sure it's installed correctly.

Are you opening the folder containing your project in VS Code? Solargraph will treat the workspace folder as the working directory and should use the .ruby-version file in its root. If that doesn't work, Code might be opening with a shell that's not compatible with rbenv; for example, rbenv is configured to work with bash but Code opens with zsh.

Another alternative is to open VS Code from the command line by cd'ing to your project folder and entering code .. If you can run solargraph -v from there, opening Code that way should work too.

Finally, you can set the path to solargraph explicitly. Try running which solargraph and set its result to solargraph.commandPath in your VS Code user or workspace settings.

I'm not sure why you have two Ruby Language Server channels. I assume one of them is Solargraph. The other might be coming from another extension, such as vscode-ruby.

lpender commented 5 years ago

Thanks @castwide !

$ solargraph -v
0.31.3

I am opening the folder containing the project in VS Code as the root of the workspace. I go to File -> Open, click "Open" on the folder. The root of the folder has a file .ruby-version with 2.3.7.

Yes, I use zsh,

I tried setting my terminal to zsh using

  "terminal.integrated.shell.osx": "/usr/local/bin/zsh",

in my settings.json.

I restart VS Code and get the same error.

After following these instructions:

Open the Command Palette (⇧⌘P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.

I typed

code .

I restart VS Code and get the same error.

which solargraph

returns

/Users/lpender/.rbenv/shims/solargraph

I added:

  "solargraph.commandPath": "/Users/lpender/.rbenv/shims/solargraph",

to settings.json, restarted VS Code.

I restart VS Code and get the same error as posted above, no change whatsoever.

Thanks!

lpender commented 5 years ago

Okay, I did the following:

brew uninstall ruby
rm -r .git/safe

Now I'm getting this:

Failed to start SolarGraph, could not find command "socket"

armstrjare commented 5 years ago

Note that the extension runs commands in a non-interactive login shell. As such, it doesn't load .zshrc. Testing a command from the interactive shell is misleading if you have shell environment setup in your .zshrc which only runs in interactive shells.

The correct way to test you are set up correctly from VSCode is via the inbuilt terminal:

/bin/zsh -l -c "bundle exec solargraph"

If you want to validate the environment:

/bin/zsh -l -c "env"
/bin/zsh -l -c "which ruby"
/bin/zsh -l -c "which solargraph"
/bin/zsh -l -c "which bundle"

I had an issue with PATH setup because I had my paths set in .zshenv but the default /etc/zprofile is automatically sourced after that and on MacOS it was prefixing my PATH in a way that caused bundle/solargraph to run outside of the expected ruby environment.

I changed my config to set up paths in ~/.zprofile instead and included source ~/.zprofile in my .zshrc

stanishev commented 5 years ago

for anyone else still running into these errors, I ended up solving it on my environment by uninstalling and reinstalling the gem..

fwiw, there was something bizarre going on with the installation of the gem.

A bit more context.

In addition to the Ruby Language Server error I was also getting:

Failed to start Solargraph: Could not find command "socket".

Trying to troubleshoot this, solargraph -v was failing:

~/repos/myrepo » solargraph -v
Could not find command "_v".

Uninstalling the gem revealed that I had two versions of solargraph installed

~/repos/myrepo » gem uninstall solargraph
Select gem to uninstall:
 1. solargraph-0.10.3
 2. solargraph-0.32.2
 3. All versions
> 3
Successfully uninstalled solargraph-0.10.3
Remove executables:
    solargraph, solargraph-runtime
....

After the uninstall completed, reinstalling the gem and reinstalling the extension in VS got things working for me. The gem version I have installed now is: solargraph-0.32.2

I am not sure how I ended up with two versions of this gem. I did try both bundle install (after adding it to the gemfile) and I subsequently did gem install solargraph, but I still don't see why that would install two different versions. I am certain that I've never tried to pull this extension or gem before (I am just now looking into using VS for ruby dev for the first time).

Samuelfaure commented 5 years ago

@armstrjare Your comment made me realize I had the solargraph gem available in two ruby versions but not the version of the project.

I ran gem install solargraph, made sure the right path to the solargraph executable was set (/home/username/.rbenv/shims/solargraph) and made sure the case 'use bundler' was unticked.

This fixed the issue. Hope it helps someone.

Note : On an unrelated issue, It doesn't work for me is I use $HOME/ instead of /home/username/.

saviour123 commented 4 years ago

Solved mine this way:

Go to Setting -> look for solargraph and scroll to bottom -> set UseBundler to false

Screenshot 2020-02-19 at 14 16 08

Uncheck it and it works.

kendofriendo commented 4 years ago

That option was already unchecked for me, and checking it made no difference.

yugoPanorama commented 4 years ago

In my case (macOS Catalina 10.15.3), I had to do the following:

rkzm commented 4 years ago

👋 @yugoPanorama I noticed that gem uninstall solargraph does not delete the solargraph installs. So I ran gem env then manually removed the gem from the INSTALLATION DIRECTORY Running gem install solargraph got everything working.

y0k4i-1337 commented 4 years ago

Note that the extension runs commands in a non-interactive login shell. As such, it doesn't load .zshrc. Testing a command from the interactive shell is misleading if you have shell environment setup in your .zshrc which only runs in interactive shells.

I had the same issue: solargraph unrecognised even with all going well in my shell (zsh). It was just when I saw this note about extension running in login mode that I realised what was the problem. Maybe this could fit in some docs?

Anyway, after moving env variables to .zlogin I was able to have solargraph working as expected. Thanks!

hennessyevan commented 4 years ago

For those rbenv/zsh users just move eval "$(rbenv init -)" to ~/.zprofile

hjhart commented 4 years ago

For nomadic users of bash or bash-it like myself, the trick was to move the PATH manipulation above the line that breaks out of ~/.bash_profile early.

# Load the Ruby manager asdf
source $HOME/.asdf/asdf.sh

# If not running interactively, don't do anything
case $- in
  *i*) ;;
    *) return;;
esac
nadnoslen commented 4 years ago

I'm using ASDF-VM to manage several versions of Ruby in my OS X world. I've had the solargraph gem fail to be found from VS Code upon opening a Ruby file for edit.

I've discovered that with ASDF fixing this can be achieved by simply running asdf reshim ruby.

To keep solargraph working You may have reshim ruby whenever your Gemfile changes following a bundle install. Quirky...

It would be ideal if the solargraph settings could accept paths like ~/.asdf/installs/ruby/2.7.1/bin/solargraph but for whatever reason this does not resolve?!

fiveNinePlusR commented 4 years ago

is it possible to run or integrate with chruby and a .ruby-version inside the project folder? perhaps have a command that we can run inline with whatever setup you use to run the scripts

/bin/zsh -l -c "bundle exec solargraph" # fails

/bin/zsh -l -c "chruby $(cat .ruby-version); bundle exec solargraph" #works as expected

avezenkov-fc commented 3 years ago

I was using rbenv so I had to rbenv init inside .zshenv or .zprofile as .zshrc is sourced only if interactive shell. VSCode doesn't use interactive shell as it could hang awaiting user input, login etc.

thubamamba commented 3 years ago

To anyone facing this issue, you need to run which solargraph

Then copy that to the Solargraph extension settings like so:

Screenshot 2021-06-10 at 15 33 05
adamcameron commented 3 years ago

I hate to go "me too", but just to confirm that @thubamamba's solution was what I needed to do too.

Yu-Chieh-Henry-Yang commented 2 years ago

I want to confirm that @thubamamba's solution works for me too. I followed the instruction and restarted the editor and solargraph works now.

JWTappert commented 2 years ago

@armstrjare your suggestions worked for me while using chruby. Once I added

# enable chruby
source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh

to my ~/.zprofile and then added source ~/.zprofile to my ~/.zshrc I was able to get solargraph to start up correctly.

CC: @fiveNinePlusR

Thank you!

slhck commented 1 year ago

FWIW, I installed solargraph through Homebrew to avoid having to specify an OS-dependent path like /Users/werner/.rbenv/… — which wouldn't work under Linux when syncing settings.

bernica commented 1 year ago

@JWTappert did that work for you both opening vscode from the OS/UI as well as from the command line (i.e. code . in the project's folder)?

mmbarness commented 1 year ago

Was tearing my hair out over this for like two weeks. What ended up being the fix, which I only discovered by accident, is a vscode setting I hadn't come across before, "terminal.integrated.automationProfile.osx". It was set to { path: "/usr/bin/zsh-with-rc" }. That wasn't valid. Setting it to match my regular osx/zsh profile, {"path": "/bin/zsh", "args": [ "-l" ]}, fixed it, along with a whole bunch of other issues. Now solargraph works great :)

awaken180-dev commented 1 year ago

I had to update the command path in both the workplace settings and the user settings for it to work for me.