Class: RubyLsp::Reek::Addon

Inherits:
Addon
  • Object
show all
Defined in:
lib/ruby_lsp/reek/addon.rb

Overview

Implements the RubyLsp::Addon interface to provide Reek linter support to Ruby LSP.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_additional_file_watchers(global_state, message_queue) ⇒ Object

Parameters:

  • global_state (GlobalState)

    The global state of the Ruby LSP server.

  • outgoing_queue (Thread::Queue)

    The outgoing message queue of the Ruby LSP server.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruby_lsp/reek/addon.rb', line 42

def self.register_additional_file_watchers(global_state, message_queue)
  return unless global_state.supports_watching_files

  message_queue << Request.new(
    id: "reek-file-watcher",
    method: "client/registerCapability",
    params: Interface::RegistrationParams.new(
      registrations: [
        Interface::Registration.new(
          id: "workspace/didChangeWatchedFilesReek",
          method: "workspace/didChangeWatchedFiles",
          register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
            watchers: [
              Interface::FileSystemWatcher.new(
                glob_pattern: "**/.reek.yml",
                kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
              )
            ]
          )
        )
      ]
    )
  )
end

Instance Method Details

#activate(global_state, message_queue) ⇒ Object

Parameters:

  • global_state (GlobalState)

    The global state of the Ruby LSP server.

  • outgoing_queue (Thread::Queue)

    The outgoing message queue of the Ruby LSP server.



27
28
29
30
31
32
33
# File 'lib/ruby_lsp/reek/addon.rb', line 27

def activate(global_state, message_queue)
  warn "Activating Reek Ruby LSP addon v#{::RubyLsp::Reek::VERSION}"
  @runner = Runner.new
  global_state.register_formatter("reek", runner)
  self.class.register_additional_file_watchers(global_state, message_queue)
  warn "Initialized Reek Ruby LSP addon v#{::RubyLsp::Reek::VERSION}"
end

#deactivatenil

Returns:

  • (nil)


36
37
38
# File 'lib/ruby_lsp/reek/addon.rb', line 36

def deactivate
  @runner = nil
end

#initializerObject



16
17
18
# File 'lib/ruby_lsp/reek/addon.rb', line 16

def initializer
  @runner = nil
end

#nameString

Returns The name of the addon.

Returns:

  • (String)

    The name of the addon.



21
22
23
# File 'lib/ruby_lsp/reek/addon.rb', line 21

def name
  "Reek: Code smell detector for Ruby"
end

#workspace_did_change_watched_files(changes) ⇒ Object

Parameters:

  • changes (Array<Hash>)

    The changes to the watched files.



68
69
70
71
72
73
# File 'lib/ruby_lsp/reek/addon.rb', line 68

def workspace_did_change_watched_files(changes)
  return unless changes.any? { |change| change[:uri].end_with?(".reek.yml") }

  runner.init!
  warn "Re-initialized Reek Ruby LSP addon v#{::RubyLsp::Reek::VERSION} due to .reek.yml file change"
end