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.

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.

[View source]

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.


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.


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.


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:) ⇒ 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.

[View source]

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:)
  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)
  @runner.formatted_source
end

#offenses(path, text, document_encoding = 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.

[View source]

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)
  diagnostic_options = {}
  diagnostic_options[:only] = config_only_options if @lint_mode || @layout_mode

  @runner.run(path, text, diagnostic_options)
  @runner.offenses.map do |offense|
    Diagnostic.new(
      document_encoding, offense, path, @cop_registry[offense.cop_name]&.first
    ).to_lsp_diagnostic(@runner.config_for_working_directory)
  end
end