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
use ara_reporting::annotation::Annotation;
use ara_reporting::builder::CharSet;
use ara_reporting::builder::ColorChoice;
use ara_reporting::builder::DisplayStyle;
use ara_reporting::builder::ReportBuilder;
use ara_reporting::error::Error;
use ara_reporting::issue::Issue;
use ara_reporting::Report;
use ara_source::source::Source;
use ara_source::source::SourceKind;
use ara_source::SourceMap;

fn main() -> Result<(), Error> {
    let map = SourceMap::new(vec![
        Source::new(
            SourceKind::Script,
            "src/main.ara",
            r#"
use function Math\add;

function main(): int {
    $value = add(1, '2');

    $value
}
"#,
        ),
        Source::new(
            SourceKind::Script,
            "vendor/some-vendor/some-lib/src/add.ara",
            r#"
namespace Math;

function add(int $a, int $b): int {
    return $a + $b;
}
"#,
        ),
    ]);

    let report = Report::new().with_issue(
        Issue::error("", "mismatched types expected `{int}`, found `{string}`")
            .with_source("src/main.ara", 68, 71)
            .with_annotation(
                Annotation::secondary("src/main.ara", 61, 64)
                    .with_message("arguments to this function are incorrect"),
            )
            .with_annotation(
                Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
                    .with_message("function defined here"),
            )
            .with_note(
                "you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
            ),
    );

    let builder = ReportBuilder::new(&map)
        .with_charset(CharSet::Unicode)
        .with_colors(ColorChoice::Always)
        .with_style(DisplayStyle::Comfortable);

    builder.print(&report)
}