zesterer / ariadne

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

Allow `Span`s to be `byte` offset based instead of `char` offset based #71

Closed brockelmore closed 1 year ago

brockelmore commented 1 year ago

I use a parser which reports code locations as byte spans instead of char spans. It would be nice if via config we could specify byte offsets instead of char offsets.

One way would be in this line:

https://github.com/zesterer/ariadne/blob/ccd465160129d2546d67f7ee78727a4098a64330/src/source.rs#L94

to switch to:

let len = line.chars().fold(0, |mut acc, i| {acc += i.len_utf8(); acc });

based on the configuration. Of note, this actually fixes some of the spacing issues like in #41 if the location producer also uses bytes.

zesterer commented 1 year ago

This will probably happen at some point, when I have more time to work on the crate. See #8.

brockelmore commented 1 year ago

Oh sorry I tried to find an issue for this but missed this! Thanks, will close this one.