Class: Solargraph::DeadEnd::Reporter

Inherits:
Solargraph::Diagnostics::Base
  • Object
show all
Defined in:
lib/solargraph/dead_end/reporter.rb

Instance Method Summary collapse

Instance Method Details

#diagnose(source, _api_map) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/solargraph/dead_end/reporter.rb', line 6

def diagnose(source, _api_map)
  return [] if source.code.empty?

  search = ::DeadEnd::CodeSearch.new(source.code, record_dir: nil).call

  blocks = search.invalid_blocks

  return [] if blocks.empty?

  result = []
  blocks.each do |block|
    explain = ::DeadEnd::ExplainSyntax.new(
      code_lines: block.lines
    ).call

    lines = ::DeadEnd::CaptureCodeContext.new(
      blocks: block,
      code_lines: search.code_lines
    ).call

    document = ::DeadEnd::DisplayCodeWithLineNumbers.new(
      lines: lines,
      terminal: @terminal,
      highlight_lines: block.lines
    ).call

    result << error_output(explain, document, block)
  end

  result
end