Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix display of annotation for double width characters #46

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

Merged
zbraniecki merged 4 commits into rust-lang:master from magurotuna:check-display-width
Sep 4, 2021

Conversation

Copy link
Contributor

@magurotuna magurotuna commented Sep 4, 2021

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

@magurotuna magurotuna Sep 4, 2021

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

@magurotuna magurotuna Sep 4, 2021

Choose a reason for hiding this comment

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

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

@magurotuna magurotuna Sep 4, 2021

Choose a reason for hiding this comment

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

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

@magurotuna magurotuna Sep 4, 2021

Choose a reason for hiding this comment

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

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
Reviewers
1 more reviewer

@zbraniecki zbraniecki zbraniecki approved these changes

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /