Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.53k stars 146 forks source link

Hidden dependency on rubocop in ruby-lsp 0.18.2 #2604

Open thedanbob opened 13 hours ago

thedanbob commented 13 hours ago

Description

Reproduction steps

Start Ruby LSP in a Rails project that isn't using Rubocop.

Error message

Ruby LSP> Skipping custom bundle setup since /home/dan/<snip>/.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 check || bundle install) 1>&2
The following gems are missing
 * ruby-lsp (0.18.2)
 * debug (1.9.2)
 * ruby-lsp-rails (0.3.16)
 * language_server-protocol (3.17.0.3)
 * prism (1.0.0)
 * rbs (3.5.3)
 * sorbet-runtime (0.5.11577)
Install missing gems with `bundle install`
Fetching gem metadata from https://rubygems.org/.........
Fetching language_server-protocol 3.17.0.3
Fetching rbs 3.5.3
Fetching sorbet-runtime 0.5.11577
Fetching prism 1.0.0
Fetching debug 1.9.2
Installing language_server-protocol 3.17.0.3
Installing rbs 3.5.3 with native extensions
Installing prism 1.0.0 with native extensions
Installing sorbet-runtime 0.5.11577
Installing debug 1.9.2 with native extensions
Fetching ruby-lsp 0.18.2
Installing ruby-lsp 0.18.2
Fetching ruby-lsp-rails 0.3.16
Installing ruby-lsp-rails 0.3.16
Bundle complete! 21 Gemfile dependencies, 89 gems now installed.
Bundled gems are installed into `./vendor/bundle`
Removing bundler (2.5.16)
 /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/ruby-lsp-0.18.2/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb:34:in `block in <class:RuboCopDiagnostic>': uninitialized constant RubyLsp::Requests::Support::RuboCopDiagnostic::RuboCop (NameError)

        sig { params(document: RubyDocument, offense: RuboCop::Cop::Offense, uri: URI::Generic).void }
                                                      ^^^^^^^
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:360:in `instance_exec'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:360:in `run_builder'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:338:in `run_sig'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:248:in `block in _on_method_added'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:449:in `run_sig_block_for_key'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:469:in `block in run_all_sig_blocks'
        from <internal:kernel>:187:in `loop'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/private/methods/_methods.rb:466:in `run_all_sig_blocks'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11577/lib/types/utils.rb:85:in `run_all_sig_blocks'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/gems/ruby-lsp-0.18.2/exe/ruby-lsp:74:in `<top (required)>'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/bin/ruby-lsp:25:in `load'
        from  /home/dan/<snip>/vendor/bundle/ruby/3.3.0/bin/ruby-lsp:25:in `<top (required)>'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `load'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `kernel_load'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/cli/exec.rb:23:in `run'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/cli.rb:455:in `exec'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/cli.rb:35:in `dispatch'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/cli.rb:29:in `start'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.16/exe/bundle:28:in `block in <top (required)>'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
        from /home/dan/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bundler-2.5.16/exe/bundle:20:in `<top (required)>'
        from /home/dan/.rbenv/versions/3.3/bin/bundle:25:in `load'
        from /home/dan/.rbenv/versions/3.3/bin/bundle:25:in `<main>'

Workaround

Add rubocop to the Gemfile.

I suspect the issue was introduced here: https://github.com/Shopify/ruby-lsp/commit/5ed8b91570b030d173e6052d769352da99558663

theodoretliu commented 11 hours ago

Also seeing the same issue today! Proposed a very simple fix but there might be a more principled one. Happy to adopt a better solution :)