ariadne
ariadne copied to clipboard
Show underlines even when first label has no message
In ariadne v0.3.0, any label would cause its span to be underlined, but also add blank lines to the output even when it had no message.
In v0.4.0, the extraneous blank lines were removed, but the behaviour regarding underlines was also changed: When the first label has no message set, no underlines at all are shown:
const SOURCE: &str = "a b c d e f";
// also supports labels with no messages to only emphasis on some areas
Report::build(ReportKind::Error, (), 34)
.with_message("Incompatible types")
.with_label(Label::new(0..1).with_color(Color::Red))
.with_label(
Label::new(2..3)
.with_color(Color::Blue)
.with_message("`b` for banana")
.with_order(1),
)
.with_label(Label::new(4..5).with_color(Color::Green))
.with_label(
Label::new(7..9)
.with_color(Color::Cyan)
.with_message("`e` for emerald"),
)
.finish()
.print(Source::from(SOURCE))
.unwrap();
(Based on examples/simple.rs
without compact
.)
This will show
Error: Incompatible types
╭─[<unknown>:?:?]
│
1 │ a b c d e f
│ │ │
│ │ ╰── `e` for emerald
│ │
│ ╰──────── `b` for banana
───╯
But when the first label for a
has a message, all spans have underlines:
Error: Incompatible types
╭─[<unknown>:?:?]
│
1 │ a b c d e f
│ ┬ ┬ ─ ─┬
│ ╰────────── a
│ │ │
│ │ ╰── `e` for emerald
│ │
│ ╰──────── `b` for banana
───╯
With this PR, underlines will be shown regardless of whether the first label has a message:
Error: Incompatible types
╭─[<unknown>:?:?]
│
1 │ a b c d e f
│ ─ ┬ ─ ─┬
│ │ │
│ │ ╰── `e` for emerald
│ │
│ ╰──────── `b` for banana
───╯
Thanks, this seems like a sensible change! I'll try to find some time to review this over the next day or two, I'm not sure I can assure myself of its correctness at just a glance.