Class: RuboCop::LSP::Diagnostic Private

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

Diagnostic for Language Server Protocol of RuboCop.

Instance Method Summary collapse

Constructor Details

#initialize(document_encoding, offense, uri, cop_class, processed_source = nil) ⇒ Diagnostic

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



21
22
23
24
25
26
27
# File 'lib/rubocop/lsp/diagnostic.rb', line 21

def initialize(document_encoding, offense, uri, cop_class, processed_source = nil)
  @document_encoding = document_encoding
  @offense = offense
  @uri = uri
  @cop_class = cop_class
  @processed_source = processed_source
end

Instance Method Details

#to_lsp_code_actionsObject

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.



29
30
31
32
33
34
35
36
# File 'lib/rubocop/lsp/diagnostic.rb', line 29

def to_lsp_code_actions
  code_actions = []

  code_actions << autocorrect_action if correctable?
  code_actions << disable_line_action

  code_actions
end

#to_lsp_diagnostic(config) ⇒ 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.

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubocop/lsp/diagnostic.rb', line 39

def to_lsp_diagnostic(config)
  highlighted = @offense.highlighted_area

  LanguageServer::Protocol::Interface::Diagnostic.new(
    message: message,
    source: 'RuboCop',
    code: @offense.cop_name,
    code_description: code_description(config),
    severity: severity,
    range: LanguageServer::Protocol::Interface::Range.new(
      start: LanguageServer::Protocol::Interface::Position.new(
        line: @offense.line - 1,
        character: to_position_character(highlighted.begin_pos)
      ),
      end: LanguageServer::Protocol::Interface::Position.new(
        line: @offense.line - 1,
        character: to_position_character(highlighted.end_pos)
      )
    ),
    data: {
      correctable: correctable?,
      code_actions: to_lsp_code_actions
    }
  )
end