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

Label fails to render when using emojis as source #62

Closed
GrandChaman opened this issue Jan 23, 2023 · 1 comment
Closed

Label fails to render when using emojis as source #62

GrandChaman opened this issue Jan 23, 2023 · 1 comment

Comments

@GrandChaman
Copy link

I noticed that when using an emoji in the source, depending on the range I specify to associate a label to it, I get a label that make sense or not.

Code to reproduce:

use ariadne::{Label, Report, ReportKind, Source};

fn main() {
    for i in 1..=4 {
        println!("Using range {:?} for a 4-bytes emoji", 0..i);
        let mut report = Report::build(ReportKind::Error, (), 0);
        report = report.with_label(Label::new(0..i).with_message("That is very haha 😂"));
        report.finish().print(Source::from("😂")).unwrap();
    }
}

The output:

Using range 0..1 for a 4-bytes emoji
Error:
   ╭─[<unknown>:1:1]
   │
 1 │ 😂
   · ┬
   · ╰── That is very haha 😂
───╯
Using range 0..2 for a 4-bytes emoji
Error:
   ╭─[<unknown>:1:1]
   │
 1 │ 😂
   · ─┬
   ·  ╰── That is very haha 😂
───╯
Using range 0..3 for a 4-bytes emoji
Error:
   ╭─[<unknown>:1:1]
   │
   ·
───╯
Using range 0..4 for a 4-bytes emoji
Error:
   ╭─[<unknown>:1:1]
   │
 1 │ ╭─▶ 😂
───╯

I think the versions with the ranges 0..1, 0..2 and 0..3 don't make sense, but I would expect the last range (0..4) to display the label correctly.

@zesterer
Copy link
Owner

Ariadne currently uses character indices, not byte indices. I consider this to be a mistake that I want to fix eventually. I'm going to close this in favour of #57, but I'm happy to reopen it if you believe there's more going on here.

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

No branches or pull requests

2 participants