1use ara_reporting::annotation::Annotation;
2use ara_reporting::builder::CharSet;
3use ara_reporting::builder::ColorChoice;
4use ara_reporting::builder::ReportBuilder;
5use ara_reporting::error::Error;
6use ara_reporting::issue::Issue;
7use ara_reporting::Report;
8use ara_reporting::ReportFooter;
9use ara_source::source::Source;
10use ara_source::source::SourceKind;
11use ara_source::source::DEFAULT_NAME;
12use ara_source::SourceMap;
13
14fn main() -> Result<(), Error> {
15 let map = SourceMap::new(vec![Source::inline(
16 SourceKind::Script,
17 r#"
18function main(): int|string {
19 $a = 1;
20 $b = 2;
21
22 $c = $a + $b;
23
24 $b = match ($a) {
25 1 => 2,
26 2 => 3,
27 default => "string",
28 };
29
30 return $c + $b;
31}
32"#,
33 )]);
34
35 let report = Report::new()
36 .with_issue(
37 Issue::error("E123", "some error here")
38 .with_source(DEFAULT_NAME, 35, 41)
39 .with_annotation(
40 Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
41 )
42 .with_note("this is a note"),
43 )
44 .with_issue(
45 Issue::warning("W123", "some warning here")
46 .with_source(DEFAULT_NAME, 29, 187)
47 .with_annotation(
48 Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
49 )
50 .with_note("this is a note"),
51 )
52 .with_issue(
53 Issue::warning("W124", "some warning here")
54 .with_source(DEFAULT_NAME, 29, 187)
55 .with_annotation(
56 Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
57 )
58 .with_note("this is a note"),
59 )
60 .with_issue(
61 Issue::note("N123", "some note here")
62 .with_source(DEFAULT_NAME, 84, 163)
63 .with_annotation(
64 Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
65 )
66 .with_annotation(
67 Annotation::secondary(DEFAULT_NAME, 121, 128)
68 .with_message("another annotation"),
69 )
70 .with_annotation(
71 Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
72 )
73 .with_note("this is a note"),
74 )
75 .with_issue(
76 Issue::help("H123", "some help here")
77 .with_source(DEFAULT_NAME, 137, 147)
78 .with_annotation(
79 Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
80 )
81 .with_note("this is a note"),
82 )
83 .with_issue(
84 Issue::bug("E123", "`match` arms have incompatible types")
85 .with_source(DEFAULT_NAME, 84, 163)
86 .with_annotation(
87 Annotation::secondary(DEFAULT_NAME, 110, 111)
88 .with_message("this is found to be of type `{int}`"),
89 )
90 .with_annotation(
91 Annotation::secondary(DEFAULT_NAME, 126, 127)
92 .with_message("this is found to be of type `{int}`"),
93 )
94 .with_annotation(
95 Annotation::secondary(DEFAULT_NAME, 148, 156)
96 .with_message("expected `{int}`, found `{string}`"),
97 )
98 .with_note("for more information about this error, try `ara --explain E0308`"),
99 )
100 .with_footer(ReportFooter::new("this is a report footer message"));
101
102 let builder = ReportBuilder::new(&map)
103 .with_colors(ColorChoice::Always)
104 .with_charset(CharSet::Unicode);
105
106 builder.print(&report)
107}