rubocop / vscode-rubocop

The official VS Code extension for the RuboCop linter and code formatter.
https://marketplace.visualstudio.com/items?itemName=rubocop.vscode-rubocop
Other
48 stars 3 forks source link

[client] No Gemfile found in the current workspace #22

Open zal-lex opened 9 months ago

zal-lex commented 9 months ago

Getting this error on opening VS Code.

I think the problem is in the project structure. It is a git repo with several folders. The backend with the rails app is one of several folders.

.git repo
├── rails-app
          ├── app
          ├── ...
           .rubocop.yml
           ...
           Gemfile
           Gemfile.lock
           ...
├── another-folder
├── one-more-folder
.gitignore
README.md
...

The Gemfile is in the rails-app folder. I need to have open full git repo with all folders simultaneously. It would be great to have a setting to pass the Gemfile path for the project/workspace

Full log:

[client] No Gemfile found in the current workspace
[client] Starting language server: rubocop --lsp
[server] RuboCop 1.54.1 language server initialized, PID 40280
cannot load such file -- rubocop-rspec
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:46:in `rescue in rescue in load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:39:in `rescue in load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:32:in `load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:21:in `load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:14:in `block (2 levels) in resolve_requires'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:13:in `each'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:13:in `block in resolve_requires'
<internal:kernel>:90:in `tap'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:12:in `resolve_requires'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader.rb:53:in `load_file'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader.rb:112:in `configuration_from_file'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_store.rb:68:in `for_dir'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_store.rb:58:in `for'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:190:in `block in process_explicit_path'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:189:in `reject'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:189:in `process_explicit_path'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:40:in `block in find'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:36:in `each'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:36:in `find'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/runner.rb:111:in `find_target_files'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/runner.rb:68:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:78:in `run_rubocop'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:51:in `block in offenses'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/server/helper.rb:26:in `redirect'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:70:in `redirect_stdout'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:51:in `offenses'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:53:in `offenses'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/routes.rb:195:in `diagnostic'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/routes.rb:84:in `block in <class:Routes>'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:34:in `call'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:34:in `block in start'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:30:in `start'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli/command/lsp.rb:14:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:118:in `run_command'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:184:in `handle_exiting_options'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:158:in `act_on_options'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:47:in `block in run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:43:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/exe/rubocop:19:in `block in <top (required)>'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/exe/rubocop:19:in `<top (required)>'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/bin/rubocop:25:in `load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/bin/rubocop:25:in `<main>'
[Error - 16:24:35] Client RuboCop: connection to server is erroring. Shutting down server.
[Error - 16:24:35] Connection to server got closed. Server will not be restarted.
[Error - 16:24:35] Stopping server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 16:24:35] Stopping server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
koic commented 9 months ago

This vscode-rubocop extension is not referencing the .git directory. This could be due to a misconfiguration in the Gemfile. Is there an entry for gem 'rubocop-rspec' in your Gemfile? Simply adding require: rubocop-rspec to .rubocop.yml is not sufficient.

zal-lex commented 9 months ago

Yes, I have both gem 'rubocop-rspec' record in the Gemfile and require: rubocop-rspec in .rubocop.yml. bundle install was executed as well

abrisse commented 9 months ago

I have exactly the same issue.

The other vs code extension ruby-robocop uses the root folders of the current workfspace to find the Gemfiles. That's not the best strategy but at least there is a workaround.

The best solution IMHO would to be find the first ancestor folder which contains the Gemfile. That would allow to works smoothly with mono repositories.

zal-lex commented 9 months ago

@abrisse I managed to fix that by installing rubocop-rspec globally.

abrisse commented 9 months ago

@zal-lex: that's a workaround of course but installing gems globally is not recommended. I don't have the same versions of the rubocop gem / the file .rubocop.yml on all projects.

grsahil20 commented 3 months ago

I have the same error. Not sure if there is a working solution.