Closed esasse closed 2 years ago
It looks like VS Code is starting Solargraph with the system installation of Ruby (2.6.0) instead of the rbenv installation (3.0.2p107).
Possible solutions:
.profile
, .bashrc
, or something else depending on your shell environment) to make sure VS Code starts with the required rbenv configuration.code .
from your workspace directory.solargraph.commandPath
in your VS Code settings to the version of the Solargraph executable you want to use. You can get the path by running which solargraph
.More information: https://solargraph.org/guides/troubleshooting
- Modify your shell profile (e.g.,
.profile
,.bashrc
, or something else depending on your shell environment) to make sure VS Code starts with the required rbenv configuration.
This should be correct, but how can I check to make sure? Everything works fine on my shell with correct versions. The only problem is with Solargraph.
- Start VS Code in a terminal by running
code .
from your workspace directory.
I've been doing this, but the problem is the same.
- Set
solargraph.commandPath
in your VS Code settings to the version of the Solargraph executable you want to use. You can get the path by runningwhich solargraph
.
This is something I didn't try before. Tried now but the problem is the same.
Does it work if you set solargraph.useBundler
to true
in your VS Code settings?
Does it work if you set
solargraph.useBundler
totrue
in your VS Code settings?
No. I've tried with true and false and the result is the same.
My only other guess is that VS Code is opening with a shell you're not expecting, e.g., VS Code uses bash
but your terminal uses zsh
. I'm not sure how to check that, but one place you can start is by opening the VS Code developer tools and checking process.env
in the console.
VS Code shell seems correct. Relevant settings returned from process.env
:
PATH: "/Users/erick/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/erick/Library/Android/sdk/tools/bin:/Users/erick/Library/Android/sdk/platform-tools:/Users/erick/Library/Android/sdk/emulator:/Users/erick/.dotnet/tools"
PWD: "/Users/erick/dev/testapps/myproject"
RBENV_SHELL: "zsh"
SHELL: "/bin/zsh"
It might be a problem with how rbenv gets added to zsh. This might help: https://programmingzen.com/installing-rbenv-on-zsh-on-macos/
It might be a problem with how rbenv gets added to zsh. This might help: https://programmingzen.com/installing-rbenv-on-zsh-on-macos/
Revised my installation and it's just like the article, so no luck there. π BTW, I have another Mac around here and the problem is the same.
One last thought: make sure you quit VS Code completely and restart it instead of restarting from the command palette. The latter might reuse the current shell and not pick up your changes.
Outside of that, I'm afraid I'm out of ideas. Hopefully someone who's more savvy with MacOS than I am can provide some help.
Yes, I was quitting VS Code completely on every try.
Anyway, thanks a lot for you quick answers and willingness to help. I could try to debug the extension code if you give me some guidance. But I have zero experience in VS Code extension development.
all I had to do to fix this issue was to add a .ruby-version
to the project. The file is there by default when you run rails new
but it has no version it's a blank file. π
all I had to do to fix this issue was to add a
.ruby-version
to the project. The file is there by default when you runrails new
but it has no version it's a blank file. π
All my projects have this file with the correct ruby version set. π Are you on macOS?
@esasse yes I'm on OSX, I also added the path to the extension settings
do this
then this
but in my case I noticed it started working after I added the version to .ruby-version
@WagnerMoreira thanks, but no luck here. Even with command path set it doesn't work.
For me, the useBundler
option seemed to stop working a few weeks ago with the same Could not find 'bundler'
error. It works if I set the commandPath
.
Update (2022-03-27): Actually, it seems the useBundler
doesn't have any effect. If I gem install solargraph
then it works, even without setting commandPath
. I'm using chruby
but I'm not sure it related to that.
For me, the
useBundler
option seemed to stop working a few weeks ago with the sameCould not find 'bundler'
error. It works if I set thecommandPath
.
This worked for me. I had to set useBundler
to false
and then set commandPath
to $HOME/.rbenv/shims/solargraph
I was experimenting with VSCode and asdf with useBundler: true
. I found that setting both the bundler path and the command path to the absolute path of their shims, i.e. the output of which bundle
and which solargraph
solved this problem for me.
I gave up and went back to RubyMine. Thanks for all that tried to help, but I had no luck, nothing worked for me.
@esasse Can I ask that you please keep the issue open, as it's an unresolved problem that many others are encountering, and it's valuable to have this information available. You can choose to unsubscribe from the notifications to prevent receiving any replies.
@andyw8 of course! I wasn't sure if I should have left it open, because it seemed to me that the proposed solutions was working for the other.
Been experimenting with this and running into similar errors. I have multiple versions of ruby installed via RVM, and a .ruby-version
file, but the extension wasn't respecting it.
We have a multi-root workspace, where one root is ruby and the other is javascript. I realized that moving the .ruby-version
file up one level (into the true project root) seemed to resolve the issue. I think I see why - solagraph was trying to start from the ui root instead of the api root and thus wasn't seeing the .ruby-version
file, I imagine.
Ideally I'd like to tell solargraph to ignore all of the roots in my multi-root workspace except the ruby one.
Somehow it's working for me now. The only two solargraph settings I have set are solargraph.bundlerPath
and solargraph.commandPath
. I'm sure that I tried them before countless times without success, but now it's working. π
I'm going to close this now that I got it working and it seems that everyone that participated in this issue was able to make it work somehow. If anyone is still having problems, I believe it's best to open another issue with the particular context. Thanks for all that contributed.
I experienced this issue and it was driving me mad. I did the following things (not sure which one specifically was fixed it, or if all 3 were needed) but hope this helps someone else. In my case, I am using frum
ruby package manager.
open workspace-file.code
(substitute your file name here)I use chruby on a mac and was running into the same problems until I did the following:
code .
Starting VS Code with code .
on Mac seems to fix a lot of common problems. The vscode-solargraph
plugin jumps through some crazy hoops to handle exceptional cases with ruby version managers, including chruby. I'm trying to make it work by default, but it's kind of a moving target.
This FAQ includes some Mac-specific issues: https://solargraph.org/guides/troubleshooting
I am having this same problem and nothing seems to fix it.
I also had the same issue. The following article was helpful
https://inspirnathan.com/posts/143-add-ruby-intellisense-in-vscode/
Having the same problem and only solution is to use solargraph
from Gemfile with useBundler: true
option in extension, as @Ken-Musau suggested. Still searching for a way to use extension without modifying Gemfile.
As in @iftheshoefritz's answer, setting the exact path of the bundler in solargraph's settings to the output of which bundle
ultimately worked for me. I have useBundler: true
set, as well.
{
...
"solargraph.useBundler": true,
"solargraph.bundlerPath": "/var/folders/q2/1cb0try95cx3ll70t6yybsfr0000gn/T/frum_76899_1718727616121/bin/bundle" # <-- Output from "which bundle"
}
This problem is intermittent and it's really killing my ruby love. Why does ruby struggle so hard to do what is trivial in other languages.
Sometimes if I just have "solargraph.useBundler": true
and it works, sometimes i've had to use the "solargraph.bunderlPath: "path/to/solargraph"
and that will work. Right now, nothing works. It's just broken. This is the only extension I have this issue with. Never have this problem with python, or rust, or go, just ruby. Very frustrating that it's been going on for years now.
I'm having trouble making the extension work. I only get Failed to start Solargraph with the following error:
My bundler version seems fine:
Environment
Bundler Build Metadata
Bundler settings
Gemfile
Gemfile
Gemfile.lock