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 formatter is set to rubocop but RuboCop was not found in the Gemfile or gemspec. #2564

Open
shrkw opened this issue Sep 18, 2024 · 8 comments
Assignees
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@shrkw
Copy link

shrkw commented Sep 18, 2024

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 LSP Rails

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
{}
User
{
  "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'
@shrkw shrkw added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Sep 18, 2024
@andyw8
Copy link
Contributor

andyw8 commented Sep 18, 2024

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
Copy link
Member

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

@shrkw
Copy link
Author

shrkw commented Sep 19, 2024

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
Copy link

LolsonX commented Sep 19, 2024

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
Copy link
Member

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.

@shrkw
Copy link
Author

shrkw commented Sep 20, 2024

I updated rubocop from 1.56.4 to 1.66.1, rubocop-rails, rubocop-rspec, however unfortunately the 2nd error still remains. git diff are following.
There are no errors displayed in the 'Output window Ruby LSP tab'.

2024-09-20 15:17:14.380 [info] (workspace) Running command: `ruby -W0 -rjson -e 'STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR" + { env: ENV.to_h, yjit: !!defined?(RubyVM:: YJIT), version: RUBY_VERSION }.to_json + "RUBY_LSP_ACTIVATION_SEPARATOR")'` in /workspace using shell: /bin/bash
2024-09-20 15:17:15.321 [info] (workspace) Initializing Ruby LSP v0.17.17...
2024-09-20 15:17:15.360 [info] (workspace) Auto detected formatter: rubocop
2024-09-20 15:17:15.360 [info] (workspace) Auto detected linters: rubocop
2024-09-20 15:17:15.360 [info] (workspace) Detected test library: rspec
2024-09-20 15:17:15.360 [info] (workspace) Finished initializing Ruby LSP!

Rubocop is working correctly when run via 'bundle exec'.

$ bundle exec rubocop --version
1.66.1

$ bundle exec rubocop app/
# detect some violations...
diff --git a/Gemfile.lock b/Gemfile.lock
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -125,3 +125,3 @@ GEM
     barby (0.6.9)
-    base64 (0.1.1)
+    base64 (0.2.0)
     bcrypt (3.1.20)
@@ -161,3 +161,3 @@ GEM
     coderay (1.1.3)
-    concurrent-ruby (1.2.3)
+    concurrent-ruby (1.3.4)
     config (5.4.0)
@@ -315,3 +315,3 @@ GEM
     httpclient (2.8.3)
-    i18n (1.14.4)
+    i18n (1.14.6)
       concurrent-ruby (~> 1.0)
@@ -322,3 +322,3 @@ GEM
     jmespath (1.6.2)
-    json (2.7.1)
+    json (2.7.2)
     json-schema (3.0.0)
@@ -385,3 +385,3 @@ GEM
     mini_portile2 (2.8.7)
-    minitest (5.22.3)
+    minitest (5.25.1)
     msgpack (1.7.2)
@@ -423,6 +423,6 @@ GEM
     os (1.1.4)
-    parallel (1.24.0)
+    parallel (1.26.3)
     paranoia (2.6.3)
       activerecord (>= 5.1, < 7.2)
-    parser (3.3.0.4)
+    parser (3.3.5.0)
       ast (~> 2.4.1)
@@ -503,3 +503,3 @@ GEM
     redis (4.7.1)
-    regexp_parser (2.9.0)
+    regexp_parser (2.9.2)
     reline (0.4.2)
@@ -551,4 +551,3 @@ GEM
     rspec-support (3.13.1)
-    rubocop (1.56.4)
-      base64 (~> 0.1.1)
+    rubocop (1.66.1)
       json (~> 2.3)
@@ -556,23 +555,17 @@ GEM
       parallel (~> 1.10)
-      parser (>= 3.2.2.3)
+      parser (>= 3.3.0.2)
       rainbow (>= 2.2.2, < 4.0)
-      regexp_parser (>= 1.8, < 3.0)
-      rexml (>= 3.2.5, < 4.0)
-      rubocop-ast (>= 1.28.1, < 2.0)
+      regexp_parser (>= 2.4, < 3.0)
+      rubocop-ast (>= 1.32.2, < 2.0)
       ruby-progressbar (~> 1.7)
       unicode-display_width (>= 2.4.0, < 3.0)
-    rubocop-ast (1.30.0)
-      parser (>= 3.2.1.0)
-    rubocop-capybara (2.20.0)
-      rubocop (~> 1.41)
-    rubocop-factory_bot (2.25.1)
-      rubocop (~> 1.41)
-    rubocop-rails (2.18.0)
+    rubocop-ast (1.32.3)
+      parser (>= 3.3.1.0)
+    rubocop-rails (2.26.1)
       activesupport (>= 4.2.0)
       rack (>= 1.1)
-      rubocop (>= 1.33.0, < 2.0)
-    rubocop-rspec (2.26.1)
-      rubocop (~> 1.40)
-      rubocop-capybara (~> 2.17)
-      rubocop-factory_bot (~> 2.22)
+      rubocop (>= 1.52.0, < 2.0)
+      rubocop-ast (>= 1.31.1, < 2.0)
+    rubocop-rspec (3.0.5)
+      rubocop (~> 1.61)
     ruby-progressbar (1.13.0)
@@ -642,3 +635,3 @@ GEM
       execjs (>= 0.3.0, < 3)
-    unicode-display_width (2.5.0)
+    unicode-display_width (2.6.0)
     unicorn (6.1.0)

@andyw8
Copy link
Contributor

andyw8 commented Sep 20, 2024

@shrkw do you have any settings in .bundle/config within your repo?

@shrkw
Copy link
Author

shrkw commented Sep 25, 2024

ah yes, I don't have .bundle/config but have some environment variables.

$ env | grep GEM
GEM_HOME=/bundle
BUNDLE_GEMFILE=/workspace/Gemfile
$ env | grep BUNDLE
BUNDLE_FORCE_RUBY_PLATFORM=true
BUNDLE_BIN=/bundle/bin
BUNDLE_GEMFILE=/workspace/Gemfile
BUNDLE_PATH=/bundle

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

4 participants