Skip to content

Conversation

magurotuna
Copy link
Contributor

Hi there.
We're using this crate in denoland/deno_lint to display pretty diagnostics of the linter. By chance, I found that this crate doesn't work well if the source includes double width characters like:

const a = "こんにちは";

Specifically, if we attempt to point to in this snippet by passing (15, 16) as range, annotate-snippets will give us:

 | 1 | const a = "こんにちは"; | ^ | 

where obviously ^ points to the wrong position.
These characters take up twice the size of ordinary characters like the alphabet, so displaying annotation for them requires special handling, which I implemented in this patch.

Comment on lines +638 to +644
let expected = r#" --> <current file>:1:1
|
1 | お寿司
| ^^^^^^ Sushi1
2 | 食べたい🍣
| ---- note: Sushi2
|"#;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With monospace fonts, this is displayed like:

image

Comment on lines +601 to +607
let expected = r#" --> <current file>:1:3
|
1 | おはよう
| _____^
2 | | ございます
| |______^ Good morning
|"#;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Comment on lines +573 to +577
let expected = r#" --> <current file>:1:7
|
1 | こんにちは、世界
| ^^^^ world
|"#;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Comment on lines +668 to +672
let expected = r#" --> <current file>:1:7
|
1 | こんにちは、新しいWorld!
| ^^^^^^^^^^^ New world
|"#;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

@zbraniecki
Copy link
Contributor

Thank you so much for the patch! It reads very clear and not just fixes the bug, but also improves the code.

@zbraniecki zbraniecki merged commit fc99036 into rust-lang:master Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants