1
2
3
4
5
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
37
38
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use ara_reporting::annotation::Annotation;
use ara_reporting::builder::CharSet;
use ara_reporting::builder::ColorChoice;
use ara_reporting::builder::ReportBuilder;
use ara_reporting::error::Error;
use ara_reporting::issue::Issue;
use ara_reporting::Report;
use ara_reporting::ReportFooter;
use ara_source::source::Source;
use ara_source::source::SourceKind;
use ara_source::source::DEFAULT_NAME;
use ara_source::SourceMap;
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}