Source-annotated diagnostic reports: data first, renderers second. Inspired by miette, codespan-reporting and ariadne.
moon add marianoguerra/error-reportimport {
"marianoguerra/error-report" @report,
"marianoguerra/error-report/render",
}///|
test {
let sources = @report.Sources::new()
let id = sources.add("greeting.txt", "hello:\n world\n universe\n")
let r = @report.Report::error("wrong indentation")
.with_code("demo::wrong_indentation")
.with_label(
@report.Label::primary(
id,
@report.Span::of_range(9, 14),
message="this group starts here",
),
)
.with_label(
@report.Label::secondary(
id,
@report.Span::of_range(16, 24),
message="but this one is less indented",
),
)
.with_help("indent every group in a block to the same column")
let config = {
..@render.default_config,
theme: @style.mono_theme,
color: Never,
}
inspect(
@render.render_string(r, sources, config),
content=(
#|error[demo::wrong_indentation]: wrong indentation
#| ╭─[ greeting.txt:2:3 ]
#| │
#|1 │ hello:
#|2 │ world
#| │ ──┬──
#| │ ╰─ this group starts here
#|3 │ universe
#| │ ───┬────
#| │ ╰─ but this one is less indented
#| │
#| ├─ help: indent every group in a block to the same column
#| ╰─
#|
),
)
}///|
test {
let sources = @report.Sources::new()
let id = sources.add("call.txt", "outer(\n a,\n b\n")
let r = @report.Report::error("unclosed delimiter").with_label(
@report.Label::primary(
id,
@report.Span::of_range(0, 16),
message="this is never closed",
),
)
let config = {
..@render.default_config,
theme: @style.mono_theme,
color: Never,
}
inspect(
@render.render_string(r, sources, config),
content=(
#|error: unclosed delimiter
#| ╭─[ call.txt:1:1 ]
#| │
#|1 │ ╭ outer(
#|2 │ │ a,
#|3 │ ├ b
#| │ ╰─ this is never closed
#| ╰─
#|
),
)
}///|
test {
let sources = @report.Sources::new()
let id = sources.add("greeting.txt", "hello:\n world\n universe\n")
let r = @report.Report::error("wrong indentation")
.with_code("demo::wrong_indentation")
.with_label(@report.Label::primary(id, @report.Span::of_range(16, 24)))
let config = {
..@render.default_config,
theme: @style.mono_theme,
color: Never,
format: Short,
}
inspect(
@render.render_string(r, sources, config),
content=(
#|greeting.txt:3:2: error[demo::wrong_indentation]: wrong indentation
#|
),
)
}pub(all) struct Label {
source : SourceId
span : Span
style : LabelStyle
message : String?
priority : Int
} derive(Eq, Debug)Install
Download zipSource-annotated diagnostic reports: data first, renderers second. Inspired by miette, codespan-reporting and ariadne.