Shopify / ruby-lsp

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

Ruby LSP formatter is set to `rubocop` but RuboCop was not found in the Gemfile or gemspec. #2564

Open shrkw opened 1 day ago

shrkw commented 1 day ago

Description

Ruby LSP and Rubocop assist does not work.

Ruby LSP Information

VS Code Version

1.93.1

Ruby LSP Extension Version

0.7.20

Ruby LSP Server Version

0.17.17

Ruby LSP Addons

Ruby Version

3.2.4

Ruby Version Manager

none

Installed Extensions

Click to expand - gitlens (15.5.1) - copilot (1.229.0) - copilot-chat (0.20.1) - vscode-rdbg (0.2.2) - ruby-extensions-pack (0.1.11) - ruby-lsp (0.7.20)

Ruby LSP Settings

Click to expand ##### Workspace ```json {} ``` ##### User ```json { "enableExperimentalFeatures": true, "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": "none" }, "customRubyCommand": "", "formatter": "auto", "linters": null, "bundleGemfile": "", "testTimeout": 30, "branch": "", "pullDiagnosticsOn": "both", "useBundlerCompose": false, "bypassTypechecker": false, "rubyExecutablePath": "", "indexing": {}, "erbSupport": true } ```

Reproduction steps

  1. Start VS Code
  2. Open in container

Then show following alert messages.

Ruby LSP formatter is set to `rubocop` but RuboCop was not found in the Gemfile or gemspec.
Source: Ruby LSP
Error loading addons: Ruby LSP Rails: wrong number of arguments (given 2, expected 1)
Source: Ruby LSP

I have rubocop in the workspace.

$ bundle exec rubocop --version
1.56.4

Output Ruby LSP tab


2024-09-18 17:19:34.591 [info] (workspace) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /workspace using shell: /bin/bash
2024-09-18 17:19:35.508 [info] (workspace) Initializing Ruby LSP v0.17.17...
2024-09-18 17:19:35.543 [info] (workspace) Auto detected formatter: rubocop
2024-09-18 17:19:35.543 [info] (workspace) Auto detected linters: rubocop
2024-09-18 17:19:35.543 [info] (workspace) Detected test library: rspec
2024-09-18 17:19:35.543 [info] (workspace) Finished initializing Ruby LSP!
2024-09-18 17:19:35.564 [info] (workspace) /bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.3/lib/ruby_lsp/ruby_lsp_rails/addon.rb:27:in `activate': wrong number of arguments (given 2, expected 1) (ArgumentError)
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `bind_call'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/addon.rb:75:in `block in load_addons'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/addon.rb:74:in `each'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/addon.rb:74:in `load_addons'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:132:in `load_addons'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:283:in `run_initialized'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:27:in `process_message'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/base_server.rb:66:in `block in start'
    from /bundle/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/base_server.rb:39:in `start'
    from /bundle/gems/ruby-lsp-0.17.17/exe/ruby-lsp:138:in `<top (required)>'
    from /bundle/bin/ruby-lsp:25:in `load'
    from /bundle/bin/ruby-lsp:25:in `<main>'

When open Ruby file, then appear in Output Window tab.

2024-09-18 17:22:02.718 [error] /bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.3/lib/ruby_lsp/ruby_lsp_rails/addon.rb:57:in `create_hover_listener': wrong number of arguments (given 3, expected 4) (ArgumentError)
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `bind_call'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/requests/hover.rb:70:in `block in initialize'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/requests/hover.rb:69:in `each'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/requests/hover.rb:69:in `initialize'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `bind_call'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/abstract/declare.rb:37:in `new'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/abstract/declare.rb:37:in `block in declare_abstract'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:588:in `text_document_hover'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:57:in `process_message'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/base_server.rb:128:in `block in new_worker'
: Error: /bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.3/lib/ruby_lsp/ruby_lsp_rails/addon.rb:57:in `create_hover_listener': wrong number of arguments (given 3, expected 4) (ArgumentError)
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `bind_call'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/requests/hover.rb:70:in `block in initialize'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/requests/hover.rb:69:in `each'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/requests/hover.rb:69:in `initialize'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `bind_call'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/abstract/declare.rb:37:in `new'
    from /bundle/gems/sorbet-runtime-0.5.11292/lib/types/private/abstract/declare.rb:37:in `block in declare_abstract'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:588:in `text_document_hover'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/server.rb:57:in `process_message'
    from /bundle/gems/ruby-lsp-0.17.17/lib/ruby_lsp/base_server.rb:128:in `block in new_worker'
andyw8 commented 1 day ago

For the first error, is it possible to share the contents of your Gemfile? (you can redact any parts that are sensitive)

For the second error, please try update to the latest ruby-lsp-rails release.

vinistock commented 1 day ago

Both errors are related to an old version of ruby-lsp-rails. Updating it should do the trick.

shrkw commented 14 hours ago

Thank you for your comments.

The 2nd error was resolved by updating the gem. Thank you!!

$ gem install ruby-lsp-rails
Fetching ruby-lsp-rails-0.3.15.gem
Successfully installed ruby-lsp-rails-0.3.15
Parsing documentation for ruby-lsp-rails-0.3.15
Installing ri documentation for ruby-lsp-rails-0.3.15
Done installing documentation for ruby-lsp-rails after 0 seconds
1 gem installed

However, the 1st error still remains. My Gemfile related to Rubocop looks like this:

group :development do
  gem 'better_errors'
  gem 'binding_of_caller', require: false
  gem 'rubocop', require: false
  gem 'rubocop-rails', require: false
  gem 'rubocop-rspec', require: false
  gem 'guard-rspec', require: false
end

Thanks,

LolsonX commented 11 hours ago

When I came across this error I tried to run rubocop on a file and it came out that it was failing. After Rubocop update it worked. Perhaps You need to update rubocop?

vinistock commented 8 hours ago

That's a good point. We only support RuboCop integration starting with v1.4.0 or higher.

If that's not the issue, then we have to start debugging to understand if the formatting requests are properly being set, what is being returned and so on.