-
Notifications
You must be signed in to change notification settings - Fork 37
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
Source code with tabs did not highlight correctly #25
Comments
Yeah, I think annotate snippets should replace tab characters with a user configurable number of spaces, and take it into account when computing underlines. This is what I do in codespan at least! |
agree! I am swamped a bit these days but will try to debug it! PRs welcomed! |
1 similar comment
agree! I am swamped a bit these days but will try to debug it! PRs welcomed! |
@legendiguess - can you retest against master? #27 got merged and I can't reproduce it anymore locally! |
@zbraniecki Here gist with minimal reproducible example https://gist.github.com/legendiguess/ccb197dac4bc77e3ae7571befc8ffbe2 |
Ah, I see. Now I understand the issue. @brendanzab 's solution is one option. The other would be to only adjust the underline calculation to account for tabs in line, but I'm not sure if display of |
|
Yeah, so it may be tricky to predict. Wondering how rustc handles that in error reporting now. |
They don't handle |
I do this using a custom writer in |
Oh, and importantly I also measure the length of strings taking the tab width into account: https://github.com/brendanzab/codespan/blob/a77e646944765dfb338185b0ba9504500afb7304/codespan-reporting/src/term/config.rs#L35-L45 |
Here's the relevant tests (excuse the not-so-nice test setup!): https://github.com/brendanzab/codespan/blob/a77e646944765dfb338185b0ba9504500afb7304/codespan-reporting/tests/term.rs#L415-L542 |
Oh wait, I understand what you're saying now, @legendiguess - yes I don't handle this properly in |
#58 can be a duplicate. |
When I dig into this issue yesterday, it turns out to be quite subtle even the That said, leading Concretely, with Generally, users are aware of the "final" result displayed on their screen, and don't care what the whitespaces there are. So, I guess there is no consensus on how a tab should be formatted "properly". We can make our rule, while it can still be different to what users "expected". |
For the record: in rustc we replace all |
I only care about things aligning on my screen, not about the exact indentation width. I never use tabs except for indentation. I guess it's the same for most people. This solution definitely gives the best bang for the (development effort) buck. |
Here some example
Slice
wheret
symbol insource
code have one space behind:That
Slice
give us that output:Now i change space behind
t
from space to tab(which still one symbol, so range of highlight should not be changed):And highlight in output is wrong now:
The text was updated successfully, but these errors were encountered: