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

Rendering bug on small spans in large spans #317

Closed
jdonszelmann opened this issue Nov 8, 2023 · 1 comment · Fixed by #316
Closed

Rendering bug on small spans in large spans #317

jdonszelmann opened this issue Nov 8, 2023 · 1 comment · Fixed by #316

Comments

@jdonszelmann
Copy link
Contributor

While using miette, I found a small but significant rendering bug in rendering arrows. The picture below shows what it looks like:
image

Of course, I can't just give you just that image to go on, so I made a minimal example:

#[derive(Error, Debug, Diagnostic)]
#[error("oops!")]
#[diagnostic(severity(Error))]
struct MyBad {
    #[source_code]
    src: NamedSource,
    #[label("big")]
    big: SourceSpan,
    #[label("small")]
    small: SourceSpan,
}
let err = MyBad {
    src: NamedSource::new("issue", "\
if true {
    a
} else {
    b
}"),
    big: (0, 32).into(),
    small: (14, 1).into(),
};
let out = fmt_report(err.into());
println!("Error: {}", out);

This prints:

r#"  × oops!
   ╭─[issue:1:1]
 1 │ ╭─▶ if true {
 2 │ │╭▶     a
   · ││    ┬
   · ││    ╰── small
 3 │ │   } else {
 4 │ │       b
 5 │ ├─▶ }
   · ╰──── big
   ╰────
"#

while I expected it to print:

r#"  × oops!
   ╭─[issue:1:1]
 1 │ ╭─▶ if true {
 2 │ │       a
   · │       ┬
   · │       ╰── small
 3 │ │   } else {
 4 │ │       b
 5 │ ├─▶ }
   · ╰──── big
   ╰────
"#

As you can see, this looks a bit like a test, which is exactly what I wrote and contributed as a pull request so the bug is reproducible. See #316.

@jdonszelmann
Copy link
Contributor Author

I ended up also fixing the butg in #316 , the failing test I contributed now passes :)

@zkat zkat closed this as completed in #316 Nov 15, 2023
zkat pushed a commit that referenced this issue Nov 15, 2023
Fixes: #317

It turned out there were two really. One related to how many characters
were added for the arrowheads in the gutter, and one where the gutter
was extended to a number of characters, including ansi escape codes.
However, because ansi escape codes are rather big, there would never be
any extension since the system thought the string was already long
enough, even though you don't actually see the width of those codes.
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 a pull request may close this issue.

1 participant