simple/
simple.rs

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::SourceMap;
12
13fn main() -> Result<(), Error> {
14    let origin = "example.ara";
15    let code = r#"
16$b = match $a {
17    1 => 2,
18    2 => 3,
19    default => "string",
20};
21"#;
22
23    let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);
24
25    let report = Report::new()
26        .with_issue(
27            Issue::error("E0417", "`match` arms have incompatible types")
28                .with_source(origin, 6, 67)
29                .with_annotation(
30                    Annotation::secondary(origin, 26, 27)
31                        .with_message("this is found to be of type `{int}`"),
32                )
33                .with_annotation(
34                    Annotation::secondary(origin, 38, 39)
35                        .with_message("this is found to be of type `{int}`"),
36                )
37                .with_annotation(
38                    Annotation::secondary(origin, 56, 64)
39                        .with_message("expected `{int}`, found `{string}`"),
40                )
41                .with_note("for more information about this error, try `ara --explain E0417`"),
42        )
43        .with_footer(
44            ReportFooter::new("this is a report footer message")
45                .with_note("this is a note message"),
46        );
47
48    let builder = ReportBuilder::new(&map)
49        .with_colors(ColorChoice::Always)
50        .with_charset(CharSet::Unicode);
51
52    builder.print(&report)
53}