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

ruby-lsp (0.20.1) fails to start due to not finding gem that is bundled in project (using rbenv 1.3.0) #2759

Closed
jm3 opened this issue Oct 23, 2024 · 6 comments
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@jm3
Copy link

jm3 commented Oct 23, 2024

Description

Ruby LSP Information

✅ latest ruby lsp vs code extension (v0.8.8)
✅ latest ruby-lsp (0.20.1)
✅ latest VS Code (1.94.2)

See issue below after debug output (ruby-lsp refuses to start, complaining about the csv gem not being installed, even though the gem is bundled by the project's Gemfile)

VS Code Version

1.94.2

Ruby LSP Extension Version

0.8.8

Ruby LSP Server Version

Unknown

Ruby LSP Addons

Ruby Version

3.3.2

Ruby Version Manager

rbenv

Installed Extensions

Click to expand
  • shades-of-purple (7.3.2)
  • vscode-theme-onedark (2.3.0)
  • vscode-erb-beautify (0.5.0)
  • insert-line-number (1.0.1)
  • format-json (1.0.3)
  • vscode-ruby-test-adapter (0.9.2)
  • vscode-markdownlint (0.56.0)
  • vscode-eslint (3.0.10)
  • githistory (0.6.20)
  • vscode-html-css (2.0.10)
  • EditorConfig (0.16.4)
  • vscode-great-icons (2.1.108)
  • prettier-vscode (11.0.0)
  • git-project-manager (1.8.2)
  • vscode-firefox-debug (2.9.10)
  • auto-rename-tag (0.1.10)
  • vscode-pull-request-github (0.98.0)
  • todo-tree (0.0.226)
  • vscode-test-explorer (2.22.1)
  • rails-fast-nav (1.3.6)
  • vscode-insertdatestring (2.3.1)
  • solidity (0.0.179)
  • karma-test-explorer (0.8.2)
  • rainbow-csv (3.12.0)
  • vscode-docker (1.29.3)
  • debugpy (2024.12.0)
  • python (2024.16.1)
  • vscode-pylance (2024.10.1)
  • remote-containers (0.388.0)
  • test-adapter-converter (0.2.0)
  • sqltools (0.28.3)
  • sqltools-driver-pg (0.5.4)
  • color-highlight (2.8.0)
  • javascript-test-runner (0.2.0)
  • fix-json (0.1.2)
  • material-icon-theme (5.11.1)
  • heroku-command (0.0.8)
  • vscode-data-preview (2.3.0)
  • vscode-commons (0.0.6)
  • vscode-xml (0.27.1)
  • vscode-yaml (1.15.0)
  • LiveServer (5.7.9)
  • ruby-lsp (0.8.8)
  • vscode-fileutils (3.10.3)
  • vscode-zipexplorer (0.3.1)
  • todo-list (1.6.0)
  • vscode-lldb (1.11.0)
  • vim (1.28.1)
  • vscode-todo-highlight (1.0.5)
  • json (2.0.2)

Ruby LSP Settings

Click to expand
Workspace
{}
User
{
  "enableExperimentalFeatures": false,
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "rbenv"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": ".ruby-lsp/Gemfile",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true
}
which ruby
/Users/jm3/.rbenv/shims/ruby
which bundler
/Users/jm3/.rbenv/shims/bundler
bundle exec irb
ruby version: ruby 3.3.2 (2024-05-30 revision e5a195edf6) [arm64-darwin23]
irb(main):001> Bundler.settings["path"]
=> nil
ls ~/.gemrc
ls: /Users/jm3/.gemrc: No such file or directory
rbenv local
3.3.2
grep ruby-lsp Gemfile
  gem 'ruby-lsp'

Issue:

ruby-lsp refuses to start, complaining about the csv gem not being installed, even though the gem is bundled by the project's Gemfile

grep csv Gemfile
gem 'csv'
bundle list |grep csv
  * csv (3.3.0)
bundle show csv
/Users/jm3/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/csv-3.3.0
Ruby LSP> Skipping custom bundle setup since /Users/jm3/Code/bright-moments/api/.ruby-lsp/Gemfile.lock already exists and is up to date
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle _2.5.21_ check || bundle _2.5.21_ install) 1>&2
The Gemfile's dependencies are satisfied
Could not find csv-3.3.0 in locally installed gems
Run `/Users/jm3/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.21/exe/bundle install` to install missing gems.
bundle exec ruby-lsp
Could not find csv-3.3.0 in locally installed gems
Run `/Users/jm3/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.21/exe/bundle install` to install missing gems.
/Users/jm3/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.21/exe/bundle install
Bundle complete! 14 Gemfile dependencies, 91 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

Project is a rails app, if that matters:

Click to expand Gemfile
BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle list
Gems included by the bundle:
  * actioncable (7.2.1.1)
  * actionmailbox (7.2.1.1)
  * actionmailer (7.2.1.1)
  * actionpack (7.2.1.1)
  * actiontext (7.2.1.1)
  * actionview (7.2.1.1)
  * activejob (7.2.1.1)
  * activemodel (7.2.1.1)
  * activerecord (7.2.1.1)
  * activestorage (7.2.1.1)
  * activesupport (7.2.1.1)
  * ast (2.4.2)
  * base64 (0.2.0)
  * bcrypt (3.1.20)
  * bigdecimal (3.1.8)
  * bootsnap (1.18.4)
  * brakeman (6.2.2)
  * builder (3.3.0)
  * byebug (11.1.3)
  * coderay (1.1.3)
  * concurrent-ruby (1.3.4)
  * connection_pool (2.4.1)
  * crass (1.0.6)
  * csv (3.3.0)
  * date (3.3.4)
  * debug (1.9.2)
  * dotenv (3.1.4)
  * drb (2.2.1)
  * erubi (1.13.0)
  * globalid (1.2.1)
  * i18n (1.14.6)
  * io-console (0.7.2)
  * irb (1.14.1)
  * json (2.7.2)
  * jwt (2.9.3)
  * language_server-protocol (3.17.0.3)
  * logger (1.6.1)
  * loofah (2.22.0)
  * mail (2.8.1)
  * marcel (1.0.4)
  * method_source (1.1.0)
  * mini_mime (1.1.5)
  * minitest (5.25.1)
  * msgpack (1.7.3)
  * net-imap (0.5.0)
  * net-pop (0.1.2)
  * net-protocol (0.2.2)
  * net-smtp (0.5.0)
  * nio4r (2.7.3)
  * nokogiri (1.16.7)
  * parallel (1.26.3)
  * parser (3.3.5.0)
  * pg (1.5.8)
  * prism (1.2.0)
  * pry (0.14.2)
  * pry-byebug (3.10.1)
  * psych (5.1.2)
  * puma (6.4.3)
  * racc (1.8.1)
  * rack (3.1.8)
  * rack-cors (2.0.2)
  * rack-session (2.0.0)
  * rack-test (2.1.0)
  * rackup (2.1.0)
  * rails (7.2.1.1)
  * rails-dom-testing (2.2.0)
  * rails-html-sanitizer (1.6.0)
  * railties (7.2.1.1)
  * rainbow (3.1.1)
  * rake (13.2.1)
  * rbs (3.6.1)
  * rdoc (6.7.0)
  * regexp_parser (2.9.2)
  * reline (0.5.10)
  * rubocop (1.67.0)
  * rubocop-ast (1.32.3)
  * ruby-lsp (0.20.1)
  * ruby-lsp-rails (0.3.20)
  * ruby-progressbar (1.13.0)
  * securerandom (0.3.1)
  * sorbet-runtime (0.5.11610)
  * stringio (3.1.1)
  * thor (1.3.2)
  * timeout (0.4.1)
  * tzinfo (2.0.6)
  * unicode-display_width (2.6.0)
  * useragent (0.16.10)
  * webrick (1.8.2)
  * websocket-driver (0.7.6)
  * websocket-extensions (0.1.5)
  * zeitwerk (2.7.1)
Use `bundle info` to print more detailed information about a gem
BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle check
The Gemfile's dependencies are satisfied

???

Issue seems like it may be related to how rails (7.2.1) bundles — when I create a new test rails app, the same issue is reproducible: ruby-lsp fails to start, complaining about a missing (bundled) gem, in this case, rubocop-rails-omakase.

Image

@jm3 jm3 added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Oct 23, 2024
@vinistock
Copy link
Member

Thank you for the bug report!

In your Ruby LSP settings, I noticed that you're setting the bundleGemfile to point to our composed bundle in the .ruby-lsp directory. Can you try removing that setting? That setting is only intended for using a separate Gemfile for development tools. If you want to use the Ruby LSP's composed bundle, then it's better to let the Ruby LSP manage it.

Also, do you happen to have any rbenv, Rubygems or Bundler settings in shell scripts?

@jm3
Copy link
Author

jm3 commented Oct 23, 2024

Weird — removing the project's Gemfile.lock and re-generating it via bundle install fixed it. Notably, this removed the following from the project's Gemfile.lock seems to have changed. I presume these are part of the default Rails / Gemfile.lock as I'm not running linux.

 PLATFORMS
   aarch64-linux
-  aarch64-linux-gnu
-  aarch64-linux-musl
   arm-linux
-  arm-linux-gnu
-  arm-linux-musl
   arm64-darwin
   x86-linux
-  x86-linux-gnu
-  x86-linux-musl
   x86_64-darwin
   x86_64-linux
-  x86_64-linux-gnu
-  x86_64-linux-musl

The part that's extremely odd to me is, putting the old Gemfile.lock back makes no difference — ruby-lsp now runs without issue with either the older or the newer Gemfile.lock.

@jm3
Copy link
Author

jm3 commented Oct 23, 2024

In your Ruby LSP settings, I noticed that you're setting the bundleGemfile to point to our composed bundle in the .ruby-lsp directory. Can you try removing that setting?

Sure, though I don't think I explicitly changed that setting. Is it possible it got changed by the extension due to my testing opening code from various directories in / outside of my project?

Also, do you happen to have any rbenv, Rubygems or Bundler settings in shell scripts?

yes, in my .zshrc (or technically, in a file that my .zshrc sources, I have:

eval "$(rbenv init - --no-rehash zsh)"

@vinistock
Copy link
Member

The Ruby LSP uses a composed bundle that is auto managed to avoid having people need to add ruby-lsp to their project's dependencies and to deliver auto updates.

It's likely that the composed lockfile (.ruby-lsp/Gemfile.lock) got into a bad state. One example of what might have happened is that Bundler had a bug recently that caused bundle check to mutate the lockfile and sometimes point to the wrong gem source.

When you change the project's lockfile, the Ruby LSP re-generates the composed bundle from scratch to ensure that we're matching all dependencies properly, so that's probably what fixed it.

I'll close the issue since the problem went away, but please let us know if you hit any issues again or if you uncover the root cause.

Sure, though I don't think I explicitly changed that setting. Is it possible it got changed by the extension due to my testing opening code from various directories in / outside of my project?

We don't mutate that setting and the default is an empty string. Not sure why it's showing .ruby-lsp/Gemfile. If you have anything in your JSON settings, remove that one.

yes, in my .zshrc (or technically, in a file that my .zshrc sources, I have:

That should be fine, you're just sourcing the version manager. The reason I asked is because sometimes users have the expectation that setting environment variables in their shell scripts will somehow affect VS Code's extension host process, which is not the case.

@jm3
Copy link
Author

jm3 commented Oct 24, 2024

Seems to recur with any new empty rails app, tho, even outside / irrespective of VS Code:

rm -rf .ruby-lsp

ruby-lsp
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle _2.5.21_ check || bundle _2.5.21_ install) 1>&2
Resolving dependencies...
The Gemfiles dependencies are satisfied
Could not find ruby-lsp-rails-0.3.21, sorbet-runtime-0.5.11611 in locally installed gems
Run `/Users/jm3/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.21/exe/bundle install` to install missing gems.

bundle
Bundle complete! 16 Gemfile dependencies, 98 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

cat .ruby-lsp/Gemfile
# This custom gemfile is automatically generated by the Ruby LSP.
# It should be automatically git ignored, but in any case: do not commit it to your repository.

eval_gemfile(File.expand_path("../Gemfile", __dir__))
gem "ruby-lsp", require: false, group: :development
gem "ruby-lsp-rails", require: false, group: :development%

@vinistock
Copy link
Member

Do you have any RubyGems, Bundler or rbenv configurations? Including both shell scripts and files such as ~/.gemrc, ~/.bundle/config and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

No branches or pull requests

2 participants