-
Notifications
You must be signed in to change notification settings - Fork 45
Fix character split when strip code #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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use std::{ | ||
cmp, | ||
fmt::{self, Display, Write}, | ||
iter::once, | ||
}; | ||
|
||
pub mod style; | ||
|
@@ -217,16 +218,21 @@ impl<'a> DisplayList<'a> { | |
} else { | ||
false | ||
}; | ||
let mut ended = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you document this variable? It's a bit unique. I also feel like there must be a way to make it simpler. The The refactor is optional, and I'm happy to land this as-is with a comment explaining the variable and its role. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I will try to document it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand the role, but I had to run an iterator in my head to derive to that conclusion so a doc string would help. |
||
let range = text | ||
.char_indices() | ||
.chain(once((text.len(), '0円'))) | ||
.skip(left) | ||
.take_while(|(_, ch)| { | ||
if ended { | ||
return false; | ||
} | ||
// Make sure that the trimming on the right will fall within the terminal width. | ||
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. | ||
// For now, just accept that sometimes the code line will be longer than desired. | ||
taken += unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1); | ||
if taken > right - left { | ||
return false; | ||
ended = true; | ||
} | ||
true | ||
}) | ||
|
@@ -238,7 +244,7 @@ impl<'a> DisplayList<'a> { | |
} | ||
}); | ||
|
||
text[range.0.expect("One character at line")..=range.1].fmt(f)?; | ||
text[range.0.expect("One character at line")..range.1].fmt(f)?; | ||
|
||
if cut_right { | ||
// We have stripped some code after the right-most span end, make it clear we did so. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[title] | ||
id = "E0308" | ||
label = "mismatched types" | ||
annotation_type = "Error" | ||
|
||
[[slices]] | ||
source = " let _: () = 42ñ" | ||
line_start = 4 | ||
origin = "$DIR/whitespace-trimming.rs" | ||
|
||
[[slices.annotations]] | ||
label = "expected (), found integer" | ||
annotation_type = "Error" | ||
range = [192, 194] | ||
|
||
[opt] | ||
color = false | ||
anonymized_line_numbers = true | ||
[opt.margin] | ||
whitespace_left = 180 | ||
span_left = 192 | ||
span_right = 194 | ||
label_right = 221 | ||
column_width = 140 | ||
max_line_len = 195 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/whitespace-trimming.rs:4:193 | ||
| | ||
LL | ... let _: () = 42ñ | ||
| ^^ expected (), found integer | ||
| |