castwide / vscode-solargraph

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

Failed to start Solargraph: Could not find 'bundler' #229

Closed esasse closed 2 years ago

esasse commented 3 years ago

I'm having trouble making the extension work. I only get Failed to start Solargraph with the following error:

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.28) required by your /Users/erick/dev/testapps/myproject/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.28`
    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>'

My bundler version seems fine:

myproject git:(master) βœ— bundle -v
Bundler version 2.2.28

Environment

Bundler       2.2.28
  Platforms   ruby, x86_64-darwin-20
Ruby          3.0.2p107 (2021-07-07 revision 0db68f023372b634603c74fca94588b457be084c) [x86_64-darwin20]
  Full Path   /Users/erick/.rbenv/versions/3.0.2/bin/ruby
  Config Dir  /Users/erick/.rbenv/versions/3.0.2/etc
RubyGems      3.2.22
  Gem Home    /Users/erick/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0
  Gem Path    /Users/erick/.gem/ruby/3.0.0:/Users/erick/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0
  User Home   /Users/erick
  User Path   /Users/erick/.gem/ruby/3.0.0
  Bin Dir     /Users/erick/.rbenv/versions/3.0.2/bin
Tools
  Git         2.32.0
  RVM         not installed
  rbenv       rbenv 1.2.0
  chruby      not installed

Bundler Build Metadata

Built At          2021-09-23
Git SHA           99b72cbd55
Released Version  true

Bundler settings

gem.coc
  Set for the current user (/Users/erick/.bundle/config): false
gem.mit
  Set for the current user (/Users/erick/.bundle/config): true
gem.test
  Set for the current user (/Users/erick/.bundle/config): "rspec"

Gemfile

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.2'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'solargraph'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (6.1.4.1)
      actionpack (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (6.1.4.1)
      actionpack (= 6.1.4.1)
      activejob (= 6.1.4.1)
      activerecord (= 6.1.4.1)
      activestorage (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      mail (>= 2.7.1)
    actionmailer (6.1.4.1)
      actionpack (= 6.1.4.1)
      actionview (= 6.1.4.1)
      activejob (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (6.1.4.1)
      actionview (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      rack (~> 2.0, >= 2.0.9)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (6.1.4.1)
      actionpack (= 6.1.4.1)
      activerecord (= 6.1.4.1)
      activestorage (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      nokogiri (>= 1.8.5)
    actionview (6.1.4.1)
      activesupport (= 6.1.4.1)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (6.1.4.1)
      activesupport (= 6.1.4.1)
      globalid (>= 0.3.6)
    activemodel (6.1.4.1)
      activesupport (= 6.1.4.1)
    activerecord (6.1.4.1)
      activemodel (= 6.1.4.1)
      activesupport (= 6.1.4.1)
    activestorage (6.1.4.1)
      actionpack (= 6.1.4.1)
      activejob (= 6.1.4.1)
      activerecord (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      marcel (~> 1.0.0)
      mini_mime (>= 1.1.0)
    activesupport (6.1.4.1)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
      zeitwerk (~> 2.3)
    addressable (2.8.0)
      public_suffix (>= 2.0.2, < 5.0)
    ast (2.4.2)
    backport (1.2.0)
    benchmark (0.1.1)
    bindex (0.8.1)
    bootsnap (1.9.1)
      msgpack (~> 1.0)
    builder (3.2.4)
    byebug (11.1.3)
    capybara (3.35.3)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (>= 1.5, < 3.0)
      xpath (~> 3.2)
    childprocess (3.0.0)
    concurrent-ruby (1.1.9)
    crass (1.0.6)
    diff-lcs (1.4.4)
    e2mmap (0.1.0)
    erubi (1.10.0)
    ffi (1.15.4)
    globalid (0.5.2)
      activesupport (>= 5.0)
    i18n (1.8.10)
      concurrent-ruby (~> 1.0)
    jaro_winkler (1.5.4)
    jbuilder (2.11.2)
      activesupport (>= 5.0.0)
    kramdown (2.3.1)
      rexml
    kramdown-parser-gfm (1.1.0)
      kramdown (~> 2.0)
    listen (3.7.0)
      rb-fsevent (~> 0.10, >= 0.10.3)
      rb-inotify (~> 0.9, >= 0.9.10)
    loofah (2.12.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (1.0.2)
    method_source (1.0.0)
    mini_mime (1.1.1)
    minitest (5.14.4)
    msgpack (1.4.2)
    nio4r (2.5.8)
    nokogiri (1.12.5-x86_64-darwin)
      racc (~> 1.4)
    parallel (1.21.0)
    parser (3.0.2.0)
      ast (~> 2.4.1)
    public_suffix (4.0.6)
    puma (5.5.0)
      nio4r (~> 2.0)
    racc (1.5.2)
    rack (2.2.3)
    rack-mini-profiler (2.3.3)
      rack (>= 1.2.0)
    rack-proxy (0.7.0)
      rack
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (6.1.4.1)
      actioncable (= 6.1.4.1)
      actionmailbox (= 6.1.4.1)
      actionmailer (= 6.1.4.1)
      actionpack (= 6.1.4.1)
      actiontext (= 6.1.4.1)
      actionview (= 6.1.4.1)
      activejob (= 6.1.4.1)
      activemodel (= 6.1.4.1)
      activerecord (= 6.1.4.1)
      activestorage (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      bundler (>= 1.15.0)
      railties (= 6.1.4.1)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.4.2)
      loofah (~> 2.3)
    railties (6.1.4.1)
      actionpack (= 6.1.4.1)
      activesupport (= 6.1.4.1)
      method_source
      rake (>= 0.13)
      thor (~> 1.0)
    rainbow (3.0.0)
    rake (13.0.6)
    rb-fsevent (0.11.0)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    regexp_parser (2.1.1)
    reverse_markdown (2.0.0)
      nokogiri
    rexml (3.2.5)
    rubocop (1.22.0)
      parallel (~> 1.10)
      parser (>= 3.0.0.0)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 1.8, < 3.0)
      rexml
      rubocop-ast (>= 1.12.0, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 1.4.0, < 3.0)
    rubocop-ast (1.12.0)
      parser (>= 3.0.1.1)
    ruby-progressbar (1.11.0)
    rubyzip (2.3.2)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.4.0)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (3.142.7)
      childprocess (>= 0.5, < 4.0)
      rubyzip (>= 1.2.2)
    semantic_range (3.0.0)
    solargraph (0.44.0)
      backport (~> 1.2)
      benchmark
      bundler (>= 1.17.2)
      diff-lcs (~> 1.4)
      e2mmap
      jaro_winkler (~> 1.5)
      kramdown (~> 2.3)
      kramdown-parser-gfm (~> 1.1)
      parser (~> 3.0)
      reverse_markdown (>= 1.0.5, < 3)
      rubocop (>= 0.52)
      thor (~> 1.0)
      tilt (~> 2.0)
      yard (~> 0.9, >= 0.9.24)
    spring (3.0.0)
    sprockets (4.0.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.2)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.4.2)
    thor (1.1.0)
    tilt (2.0.10)
    turbolinks (5.2.1)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (2.0.4)
      concurrent-ruby (~> 1.0)
    unicode-display_width (2.1.0)
    web-console (4.1.0)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webdrivers (4.6.1)
      nokogiri (~> 1.6)
      rubyzip (>= 1.3.0)
      selenium-webdriver (>= 3.0, < 4.0)
    webpacker (5.4.3)
      activesupport (>= 5.2)
      rack-proxy (>= 0.6.1)
      railties (>= 5.2)
      semantic_range (>= 2.3.0)
    websocket-driver (0.7.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    yard (0.9.26)
    zeitwerk (2.4.2)

PLATFORMS
  x86_64-darwin-20

DEPENDENCIES
  bootsnap (>= 1.4.4)
  byebug
  capybara (>= 3.26)
  jbuilder (~> 2.7)
  listen (~> 3.3)
  puma (~> 5.0)
  rack-mini-profiler (~> 2.0)
  rails (~> 6.1.4, >= 6.1.4.1)
  sass-rails (>= 6)
  selenium-webdriver
  solargraph
  spring
  sqlite3 (~> 1.4)
  turbolinks (~> 5)
  tzinfo-data
  web-console (>= 4.1.0)
  webdrivers
  webpacker (~> 5.0)

RUBY VERSION
   ruby 3.0.2p107

BUNDLED WITH
   2.2.28
castwide commented 3 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:

More information: https://solargraph.org/guides/troubleshooting

esasse commented 3 years ago
  • 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 running which solargraph.

This is something I didn't try before. Tried now but the problem is the same.

castwide commented 3 years ago

Does it work if you set solargraph.useBundler to true in your VS Code settings?

esasse commented 3 years ago

Does it work if you set solargraph.useBundler to true in your VS Code settings?

No. I've tried with true and false and the result is the same.

castwide commented 3 years ago

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.

esasse commented 3 years ago

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"
castwide commented 3 years ago

It might be a problem with how rbenv gets added to zsh. This might help: https://programmingzen.com/installing-rbenv-on-zsh-on-macos/

esasse commented 3 years ago

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.

castwide commented 3 years ago

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.

esasse commented 3 years ago

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.

WagnerMoreira commented 3 years ago

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. πŸŽ‰

esasse commented 3 years ago

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 my projects have this file with the correct ruby version set. 😟 Are you on macOS?

WagnerMoreira commented 3 years ago

@esasse yes I'm on OSX, I also added the path to the extension settings

do this Screen Shot 2021-10-28 at 11 03 28 AM

then this Screen Shot 2021-10-28 at 11 03 05 AM

but in my case I noticed it started working after I added the version to .ruby-version

esasse commented 3 years ago

@WagnerMoreira thanks, but no luck here. Even with command path set it doesn't work.

andyw8 commented 3 years ago

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.

lrdiv commented 2 years ago

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.

This worked for me. I had to set useBundler to false and then set commandPath to $HOME/.rbenv/shims/solargraph

iftheshoefritz commented 2 years ago

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.

esasse commented 2 years ago

I gave up and went back to RubyMine. Thanks for all that tried to help, but I had no luck, nothing worked for me.

andyw8 commented 2 years ago

@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.

esasse commented 2 years ago

@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.

gregawoods commented 2 years ago

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.

esasse commented 2 years ago

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. πŸŽ‰

esasse commented 2 years ago

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.

synth commented 2 years ago

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.

drewnichols commented 2 years ago

I use chruby on a mac and was running into the same problems until I did the following:

castwide commented 2 years ago

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

owenduncansnobel commented 1 year ago

I am having this same problem and nothing seems to fix it.

kenmusau commented 1 year ago

I also had the same issue. The following article was helpful

https://inspirnathan.com/posts/143-add-ruby-intellisense-in-vscode/

alexamy commented 1 year ago

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.

lreardon commented 4 months ago

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.

In settings.json

{
    ...
    "solargraph.useBundler": true,
    "solargraph.bundlerPath": "/var/folders/q2/1cb0try95cx3ll70t6yybsfr0000gn/T/frum_76899_1718727616121/bin/bundle" # <-- Output from "which bundle"
}
Oglopf commented 3 months ago

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.