Closed MattX closed 1 year ago
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?
@Benjamin-L oops, I didn't see your message before merging. Yeah, let's address that, too.
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/miette#223. Unit tests provided in that issue by @Benjamin-L (lightly modified).