Module: RubyLsp::Reek::Diagnostic

Defined in:
lib/ruby_lsp/reek/diagnostic.rb

Overview

Translates a Reek smell warning into the LSP diagnostic that Ruby LSP reports back to the editor.

Class Method Summary collapse

Class Method Details

.from_warning(warning) ⇒ RubyLsp::Interface::Diagnostic

Returns The diagnostic.

Parameters:

  • warning (Reek::SmellWarning)

    The warning to convert to a diagnostic.

Returns:

  • (RubyLsp::Interface::Diagnostic)

    The diagnostic.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_lsp/reek/diagnostic.rb', line 10

def self.from_warning(warning)
  lines = warning.lines
  ::RubyLsp::Interface::Diagnostic.new(
    range: ::RubyLsp::Interface::Range.new(
      start: ::RubyLsp::Interface::Position.new(
        line: lines.first - 1,
        character: 0
      ),
      end: ::RubyLsp::Interface::Position.new(
        line: lines.last - 1,
        character: 0
      )
    ),
    severity: Constant::DiagnosticSeverity::WARNING,
    code: warning.smell_type,
    code_description: ::RubyLsp::Interface::CodeDescription.new(href: warning.explanatory_link),
    source: "Reek",
    message: warning.message
  )
end