Open lpender opened 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.
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!
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"
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
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).
@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/.
Solved mine this way:
Go to Setting -> look for solargraph and scroll to bottom -> set UseBundler
to false
Uncheck it and it works.
That option was already unchecked for me, and checking it made no difference.
In my case (macOS Catalina 10.15.3), I had to do the following:
gem uninstall solargraph
(to get rid of the install I did through Bundler)gem install solargraph
(reinstalling)gem install nokogiri
(a dependency that somehow was missing from the Solargraph gem?)code .
. If I try starting from the macOS Dock, Solargraph won't load.👋 @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.
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!
For those rbenv/zsh users just move eval "$(rbenv init -)"
to ~/.zprofile
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
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?!
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
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.
To anyone facing this issue, you need to run
which solargraph
Then copy that to the Solargraph extension settings like so:
I hate to go "me too", but just to confirm that @thubamamba's solution was what I needed to do too.
I want to confirm that @thubamamba's solution works for me too. I followed the instruction and restarted the editor and solargraph works now.
@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!
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.
@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)?
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 :)
I had to update the command path in both the workplace settings and the user settings for it to work for me.
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,
rbenv
.ruby
version2.3.7
as specified by my.ruby-version
file.solargraph
gem underdevelopment
in myGemfile
and run abundle install
When I start VSCode I see the following in the bottom right corner:
And in the bottom tab I see the following:
Some more context:
All I'm looking for is some documentation explaining how things work... i.e. :
.ruby-version
is2.3.7
, why issolargraph
looking in2.3.1
and2.3.0
?I really just have no idea what's going on. Is there something I can read ?
Thanks!