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::ReportCollection;
9use ara_reporting::ReportFooter;
10use ara_source::source::Source;
11use ara_source::source::SourceKind;
12use ara_source::SourceMap;
13
14fn main() -> Result<(), Error> {
15 let first_origin = "example.ara";
16 let first_code = r#"
17$b = match $a {
18 1 => 2,
19 2 => 3,
20 default => "string",
21};
22"#;
23
24 let second_origin = "example-2.ara";
25 let second_code = r#"
26function foo(Bar&float) {}
27"#;
28
29 let map = SourceMap::new(vec![
30 Source::new(SourceKind::Script, first_origin, first_code),
31 Source::new(SourceKind::Script, second_origin, second_code),
32 ]);
33
34 let first_report = Report::new()
35 .with_issue(
36 Issue::error("E0417", "`match` arms have incompatible types")
37 .with_source(first_origin, 6, 67)
38 .with_annotation(
39 Annotation::secondary(first_origin, 26, 27)
40 .with_message("this is found to be of type `{int}`"),
41 )
42 .with_annotation(
43 Annotation::secondary(first_origin, 38, 39)
44 .with_message("this is found to be of type `{int}`"),
45 )
46 .with_annotation(
47 Annotation::secondary(first_origin, 56, 64)
48 .with_message("expected `{int}`, found `{string}`"),
49 )
50 .with_note("for more information about this error, try `ara --explain E0417`"),
51 )
52 .with_footer(
53 ReportFooter::new("this is a report footer message")
54 .with_note("this is a note message"),
55 );
56
57 let second_report = Report::new()
58 .with_issue(
59 Issue::error(
60 "P0015",
61 "scalar type `float` cannot be used in an intersection",
62 )
63 .with_source(second_origin, 18, 23)
64 .with_annotation(
65 Annotation::secondary(second_origin, 17, 19)
66 .with_message("scalar type `float` cannot be used in an intersection"),
67 )
68 .with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
69 .with_note("try using a different type for the intersection."),
70 )
71 .with_issue(Issue::bug("B0001", "failed to read the file"))
72 .with_footer(
73 ReportFooter::new("this is a report footer message")
74 .with_note("this is a note message"),
75 );
76
77 let reports: ReportCollection = vec![&first_report, &second_report];
78
79 let builder = ReportBuilder::new(&map)
80 .with_colors(ColorChoice::Always)
81 .with_charset(CharSet::Unicode);
82
83 builder.print(&reports)
84}