Class: TRuby::ErrorReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/t_ruby/error_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter: nil) ⇒ ErrorReporter

Returns a new instance of ErrorReporter.



7
8
9
10
11
# File 'lib/t_ruby/error_reporter.rb', line 7

def initialize(formatter: nil)
  @diagnostics = []
  @formatter = formatter || DiagnosticFormatter.new
  @source_cache = {}
end

Instance Attribute Details

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



5
6
7
# File 'lib/t_ruby/error_reporter.rb', line 5

def diagnostics
  @diagnostics
end

Instance Method Details

#add(diagnostic) ⇒ Object



13
14
15
# File 'lib/t_ruby/error_reporter.rb', line 13

def add(diagnostic)
  @diagnostics << diagnostic
end

#add_parse_error(error, file:, source: nil) ⇒ Object



22
23
24
25
# File 'lib/t_ruby/error_reporter.rb', line 22

def add_parse_error(error, file:, source: nil)
  source ||= load_source(file)
  add(Diagnostic.from_parse_error(error, file: file, source: source))
end

#add_scan_error(error, file:, source: nil) ⇒ Object



27
28
29
30
# File 'lib/t_ruby/error_reporter.rb', line 27

def add_scan_error(error, file:, source: nil)
  source ||= load_source(file)
  add(Diagnostic.from_scan_error(error, file: file, source: source))
end

#add_type_check_error(error, file:, source: nil) ⇒ Object



17
18
19
20
# File 'lib/t_ruby/error_reporter.rb', line 17

def add_type_check_error(error, file:, source: nil)
  source ||= load_source(file)
  add(Diagnostic.from_type_check_error(error, file: file, source: source))
end

#clearObject



44
45
46
47
# File 'lib/t_ruby/error_reporter.rb', line 44

def clear
  @diagnostics.clear
  @source_cache.clear
end

#error_countObject



36
37
38
# File 'lib/t_ruby/error_reporter.rb', line 36

def error_count
  @diagnostics.count { |d| d.severity == Diagnostic::SEVERITY_ERROR }
end

#has_errors?Boolean

Returns:



32
33
34
# File 'lib/t_ruby/error_reporter.rb', line 32

def has_errors?
  @diagnostics.any? { |d| d.severity == Diagnostic::SEVERITY_ERROR }
end

#reportObject



40
41
42
# File 'lib/t_ruby/error_reporter.rb', line 40

def report
  @formatter.format_all(@diagnostics)
end