Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show underlines even when first label has no message #114

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

narpfel
Copy link

@narpfel narpfel commented Apr 26, 2024

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
───╯

@zesterer
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants