Class: RubyLsp::RuboCop::RuntimeAdapter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lsp/rubocop/runtime_adapter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides an adapter to bridge RuboCop’s built-in LSP runtime with Ruby LSP’s add-on.

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(message_queue) ⇒ RuntimeAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RuntimeAdapter.

API:

  • private



10
11
12
13
# File 'lib/ruby_lsp/rubocop/runtime_adapter.rb', line 10

def initialize(message_queue)
  @message_queue = message_queue
  reload_config
end

Instance Method Details

#reload_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_lsp/rubocop/runtime_adapter.rb', line 15

def reload_config
  @runtime = nil
  options, _paths = ::RuboCop::Options.new.parse([])

  config_store = ::RuboCop::ConfigStore.new
  config_store.apply_options!(options)
  @runtime = ::RuboCop::LSP::Runtime.new(config_store)
rescue ::RuboCop::Error => e
  @message_queue << Notification.window_show_message(
    "RuboCop configuration error: #{e.message}. Formatting will not be available.",
    type: Constant::MessageType::ERROR
  )
end

#run_diagnostic(uri, document) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_lsp/rubocop/runtime_adapter.rb', line 29

def run_diagnostic(uri, document)
  with_error_handling do
    @runtime.offenses(
      uri_to_path(uri),
      document.source,
      document.encoding,
      prism_result: prism_result(document)
    )
  end
end

#run_formatting(uri, document) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_lsp/rubocop/runtime_adapter.rb', line 40

def run_formatting(uri, document)
  with_error_handling do
    @runtime.format(
      uri_to_path(uri),
      document.source,
      command: 'rubocop.formatAutocorrects',
      prism_result: prism_result(document)
    )
  end
end

#run_range_formatting(_uri, _partial_source, _base_indentation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



51
52
53
54
55
56
57
# File 'lib/ruby_lsp/rubocop/runtime_adapter.rb', line 51

def run_range_formatting(_uri, _partial_source, _base_indentation)
  # Not yet supported. Should return the formatted version of `partial_source` which is
  # a partial selection of the entire document. For example, it should not try to add
  # a frozen_string_literal magic comment and all style corrections should start from
  # the `base_indentation`.
  nil
end