Class: RuboCop::LSP::Runtime Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/lsp/runtime.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.

Runtime for Language Server Protocol of RuboCop.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_store) ⇒ Runtime

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 Runtime.

API:

  • private



22
23
24
25
26
27
28
29
30
31
# File 'lib/rubocop/lsp/runtime.rb', line 22

def initialize(config_store)
  RuboCop::LSP.enable

  @runner = RuboCop::Lsp::StdinRunner.new(config_store)
  @cop_registry = RuboCop::Cop::Registry.global.to_h

  @safe_autocorrect = true
  @lint_mode = false
  @layout_mode = false
end

Instance Attribute Details

#layout_mode=(value) ⇒ Object (writeonly)

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



20
21
22
# File 'lib/rubocop/lsp/runtime.rb', line 20

def layout_mode=(value)
  @layout_mode = value
end

#lint_mode=(value) ⇒ Object (writeonly)

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



20
21
22
# File 'lib/rubocop/lsp/runtime.rb', line 20

def lint_mode=(value)
  @lint_mode = value
end

#safe_autocorrect=(value) ⇒ Object (writeonly)

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



20
21
22
# File 'lib/rubocop/lsp/runtime.rb', line 20

def safe_autocorrect=(value)
  @safe_autocorrect = value
end

Instance Method Details

#format(path, text, command:, prism_result: nil) ⇒ 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



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/lsp/runtime.rb', line 33

def format(path, text, command:, prism_result: nil)
  safe_autocorrect = if command
                       command == 'rubocop.formatAutocorrects'
                     else
                       @safe_autocorrect
                     end

  formatting_options = { autocorrect: true, safe_autocorrect: safe_autocorrect }
  formatting_options[:only] = config_only_options if @lint_mode || @layout_mode

  @runner.run(path, text, formatting_options, prism_result: prism_result)
  @runner.formatted_source
end

#offenses(path, text, document_encoding = nil, prism_result: nil) ⇒ 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



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/lsp/runtime.rb', line 47

def offenses(path, text, document_encoding = nil, prism_result: nil)
  diagnostic_options = {}
  diagnostic_options[:only] = config_only_options if @lint_mode || @layout_mode

  @runner.run(path, text, diagnostic_options, prism_result: prism_result)
  processed_source = @runner.processed_source
  config = @runner.config_for_working_directory
  @runner.offenses.map do |offense|
    build_diagnostic(offense, path, document_encoding, processed_source, config)
  end
end