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

Undefined method log for RuboCop::Lsp::Server #11992

Closed
asartalo opened this issue Jun 28, 2023 · 1 comment · Fixed by #11993
Closed

Undefined method log for RuboCop::Lsp::Server #11992

asartalo opened this issue Jun 28, 2023 · 1 comment · Fixed by #11993
Labels

Comments

@asartalo
Copy link

I had a bad .rubocop.yml configuration and the LSP server wanted to show the error but it couldn't find the log method to use for that. I use VSCode with a rubocop extension (https://github.com/rubocop/vscode-rubocop) that uses the LSP.

I was able to workaround the issue by manually editing the LSP server source code on disk and adding a log method:

module RuboCop
  module Lsp
    # Language Server Protocol of RuboCop.
    # @api private
    class Server

      # Inserted method below...
      def log(message)
        Logger.log(message)
      end

      def initialize(config_store)
        @reader = LanguageServer::Protocol::Transport::Io::Reader.new($stdin)
        @writer = LanguageServer::Protocol::Transport::Io::Writer.new($stdout)
        @runtime = RuboCop::Lsp::Runtime.new(config_store)
        @routes = Routes.new(self)
      end
      # ... more code ...
    end
  end
end

Expected behavior

I expected to see some error log.

Actual behavior

LSP Server crashes because of missing method with the following output:

undefined method `log' for #<RuboCop::Lsp::Server:0x000000010f357d38 @reader=#<LanguageServer::Protocol::Transport::Io::Reader:0x000000010f357c20 @io=#<IO:<STDIN>>>, @writer=#<LanguageServer::Protocol::Transport::Io::Writer:0x000000010f357b30 @io=#<IO:<STDOUT>>>, @runtime=#<RuboCop::Lsp::Runtime:0x000000010f357a68 @config_store=#<RuboCop::ConfigStore:0x000000010f11f890 @options_config=nil, @path_cache={"[redacted]"=>"[redacted]/.rubocop.yml"}, @object_cache={}, @validated=true>, @logged_paths=[]>, @routes=#<RuboCop::Lsp::Routes:0x000000010f357928 @server=#<RuboCop::Lsp::Server:0x000000010f357d38 ...>, @text_cache={"file:///[redacted]/api.rb"=>"# frozen_string_literal: true\n\nrequire_relative \"api/callbacks_delegator\"\n\nrequire_relative 'api/[source redacted]"}>>

          log("Error #{e.class} #{e.message[0..100]}")
          ^^^
Did you mean?  load
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/lsp/server.rb:39:in `rescue in block in start'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/lsp/server.rb:31:in `block in start'
[redacted]/.rbenv/versions/3.1.2/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'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/lsp/server.rb:30:in `start'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli/command/lsp.rb:14:in `run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli/command.rb:11:in `run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli/environment.rb:18:in `run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli.rb:118:in `run_command'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli.rb:184:in `handle_exiting_options'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli.rb:158:in `act_on_options'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli.rb:47:in `block in run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli.rb:77:in `profile_if_needed'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/lib/rubocop/cli.rb:43:in `run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/exe/rubocop:19:in `block in <top (required)>'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.53.1/exe/rubocop:19:in `<top (required)>'
[redacted]/.rbenv/versions/3.1.2/bin/rubocop:25:in `load'
[redacted]/.rbenv/versions/3.1.2/bin/rubocop:25:in `<top (required)>'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:58:in `load'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:58:in `kernel_load'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:23:in `run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/cli.rb:483:in `exec'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/cli.rb:31:in `dispatch'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/cli.rb:25:in `start'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/exe/bundle:48:in `block in <top (required)>'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
[redacted]/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.14/exe/bundle:36:in `<top (required)>'
[redacted]/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
[redacted]/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'

I can't use rubocop --debug because the extension calls rubocop itself and I don't know how to modify it.

Steps to reproduce the problem

Screenshot 2023-06-28 at 7 44 19 PM

RuboCop version

 bundle exec rubocop -V
1.53.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.2) [x86_64-darwin22]
  - rubocop-performance 1.18.0
@koic koic added the bug label Jun 28, 2023
koic added a commit to koic/rubocop that referenced this issue Jun 28, 2023
Fixes rubocop#11992.

This PR fixes an unexpected `NoMethodError` for LSP mode when an internal error occurs.
bbatsov pushed a commit that referenced this issue Jun 28, 2023
Fixes #11992.

This PR fixes an unexpected `NoMethodError` for LSP mode when an internal error occurs.
@asartalo
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants