Skip to content
← Back

src/analysis/diagnostics_collector.ghul

1
@@IF.dotnet()
2
3
namespace Analysis is
4
use Collections.LIST
5
use Collections.Iterable
6
7
use Ghul.Pipes
8
9
use Logging.DiagnosticSeverity
10
use Logging.DIAGNOSTIC_MESSAGE
11
12
// Drains the analyser's diagnostics store into the given lists,
13
// walking the store's retained DIAGNOSTIC_MESSAGE objects directly.
14
// Every path the logger currently has a (possibly empty) diagnostics
15
// list for joins `checked_paths`, which the client uses to clear
16
// stale squiggles for files that came back clean. The lists are
17
// mutated rather than returned because every handler ultimately
18
// assembles a Response.DIAGNOSTICS variant at the write site, where
19
// it also has the per-handler phase / elapsed_ms / compile_needed
20
// values to pass to the constructor.
21
class DIAGNOSTICS_COLLECTOR is
22
collect_into(
23
logger: Logging.Logger,
24
diagnostics: LIST[Protocol.DIAGNOSTIC],
25
checked_paths: LIST[string]
26
) static is
27
for path in logger.diagnostic_paths do
28
checked_paths.add(path)
29
30
for diagnostic in logger.diagnostics_for(path) do
31
let location = diagnostic.location
32
33
// A fatal/exception frame is downgraded to hint
34
// severity on the wire rather than surfaced as a
35
// blocking error.
36
let severity =
37
if diagnostic.is_fatal then
38
cast int(DiagnosticSeverity.HINT)
39
else
40
cast int(diagnostic.severity)
41
fi
42
43
let dto = Protocol.DIAGNOSTIC(
44
path,
45
location.start_line,
46
location.start_column,
47
location.end_line,
48
location.end_column + 1,
49
severity,
50
diagnostic.text.replace('\n', ' '),
51
diagnostic.code ?? ""
52
)
53
54
if let related_locations = diagnostic.related then
55
let related = LIST[Protocol.RELATED_LOCATION_DTO]()
56
57
for r in related_locations do
58
related.add(Protocol.RELATED_LOCATION_DTO(_location_dto(r.location), r.message))
59
od
60
61
dto.related = related
62
fi
63
64
diagnostics.add(dto)
65
od
66
od
67
si
68
69
// Same end-column-exclusive convention as the diagnostic's own
70
// range (see collect_into), so a related location composes with
71
// it under one coordinate system.
72
_location_dto(location: Source.LOCATION) -> Protocol.LOCATION_DTO static is
73
return Protocol.LOCATION_DTO(
74
location.file_name,
75
location.start_line,
76
location.start_column,
77
location.end_line,
78
location.end_column + 1
79
)
80
si
81
si
82
si