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

Extend error text span to whole code points #312

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

MattX
Copy link
Contributor

@MattX MattX commented Nov 2, 2023

This fixes a panic when an error starts inside a Unicode code point. The range is extended to start (or end) at the beginning (or end) of the character inside which the byte offset is located.

Fixes #223. Unit tests provided in that issue by @Benjamin-L (lightly modified).

This fixes a panic when an error starts inside a Unicode code point. The
range is extended to start (or end) at the beginning (or end) of the
character inside which the byte offset is located.

Fixes zkat#223.
Copy link
Owner

@zkat zkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh hey awesome! Thanks!

@Benjamin-L
Copy link
Contributor

There's one more edge case here that might be worth fixing now or might be worth handling in a later PR:

    let src = "source\n  👼🏼text\n    here".to_string();
    let err = MyBad {
        src: NamedSource::new("bad_file.rs", src),
        highlight: (10, 0).into(),
    };

Produces

---- single_line_with_wide_char_unaligned_span_empty stdout ----
Error: oops::my::bad

  × oops!
   ╭─[bad_file.rs:2:4]
 1 │ source
 2 │   👼🏼text
   ·   ─▲
   ·    ╰── this bit here
 3 │     here
   ╰────
  help: try doing it better next time?

I would probably expect either

---- single_line_with_wide_char_unaligned_span_empty stdout ----
Error: oops::my::bad

  × oops!
   ╭─[bad_file.rs:2:3]
 1 │ source
 2 │   👼🏼text
   ·   ▲
   ·   ╰── this bit here
 3 │     here
   ╰────
  help: try doing it better next time?

or maybe

---- single_line_with_wide_char_unaligned_span_empty stdout ----
Error: oops::my::bad

  × oops!
   ╭─[bad_file.rs:2:3]
 1 │ source
 2 │   👼🏼text
   ·    ▲
   ·    ╰── this bit here
 3 │     here
   ╰────
  help: try doing it better next time?

@zkat zkat merged commit a8b4ae0 into zkat:main Nov 2, 2023
11 checks passed
@zkat
Copy link
Owner

zkat commented Nov 2, 2023

@Benjamin-L oops, I didn't see your message before merging. Yeah, let's address that, too.

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.

Graphical handler panics when span endpoints are not aligned to char boundaries
3 participants