zesterer / ariadne

A fancy diagnostics & error reporting crate
https://crates.io/crates/ariadne
MIT License
1.74k stars 76 forks source link

Labels without messages still create extra vertical space #51

Closed kaikalii closed 1 year ago

kaikalii commented 1 year ago

Consider this example:

use ariadne::*;

const TEXT: &str = "a b c d";

fn report_n_labels(n: usize) {
    let mut report = Report::build(ReportKind::Error, (), 0);
    for i in 0..n {
        report = report.with_label(Label::new(i * 2..i * 2 + 1));
    }
    report.finish().print(Source::from(TEXT)).unwrap();
}

fn main() {
    for n in 1..=4 {
        report_n_labels(n);
    }
}

This gives output:

Error: 
   ╭─[<unknown>:1:1]
   │
 1 │ a b c d
   · ─
   ·
───╯
Error:
   ╭─[<unknown>:1:1]
   │
 1 │ a b c d
   · ─ ─
   ·
   ·
   ·
───╯
Error:
   ╭─[<unknown>:1:1]
   │
 1 │ a b c d
   · ─ ─ ─
   ·
   ·
   ·
   ·
   ·
───╯
Error:
   ╭─[<unknown>:1:1]
   │
 1 │ a b c d
   · ─ ─ ─ ─
   ·
   ·
   ·
   ·
   ·
   ·
   ·
───╯

It looks like labels add extra vertical space for their messages even if they don't have messages. This occurs with compact mode too. I think this is undesirable.

zesterer commented 1 year ago

Yes, this is undesirable. I'll make sure to fix this for the refactor.

Override-6 commented 1 year ago

I think i've fixed it in my fork image image

zesterer commented 1 year ago

This is now resolved, thanks @Override-6!