-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Fix a few more diagnostic differences from Ruff #19806
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 6 commits
91aec07
b649289
6ad20b4
0f8c62c
e4322e7
ee971ea
47815c7
e02704a
9bfeaaf
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1273,13 +1273,17 @@ fn format_header<'a>( | |||||||||||||
| .. | ||||||||||||||
| } = item | ||||||||||||||
| { | ||||||||||||||
| if main_range >= range.0 && main_range < range.1 + max(*end_line as usize, 1) { | ||||||||||||||
| let end_of_range = range.1 + max(*end_line as usize, 1); | ||||||||||||||
| if main_range >= range.0 && main_range < end_of_range { | ||||||||||||||
| let char_column = text[0..(main_range - range.0).min(text.len())] | ||||||||||||||
| .chars() | ||||||||||||||
| .count(); | ||||||||||||||
| col = char_column + 1; | ||||||||||||||
| line_offset = lineno.unwrap_or(1); | ||||||||||||||
| break; | ||||||||||||||
| } else if main_range == end_of_range { | ||||||||||||||
| line_offset = lineno.map_or(1, |line| line + 1); | ||||||||||||||
|
Member
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. Is the I think it would also be okay to say
Contributor
Author
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. Yes, the +1 is to point to the next line to match Ruff's current behavior: Lines 173 to 178 in c401a6d
I agree with you that 29:2 would make sense and more closely align with the rendering, though. One issue I ran into here was that (naively) computing the column breaks some other annotate-snippets tests. Maybe that's a sign that it's not the right fix. I'll look at this a bit more.
Contributor
Author
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 have a more robust fix working, but this will also be a mismatch from the
Member
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. Fixing
Contributor
Author
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. Yeah I definitely want them to match, I was more wondering if you'd rather align on this new behavior or preserve the old behavior. I'll have to double check the other output formats too. Hopefully they all use the line index. I guess
Member
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'd prefer aligning on the new behavior. I think the existing behavior is even confusing in the context of the new newline at end of file because it suggests that there's a newline (which obviously there isn't)
Contributor
Author
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. For future reference, we discussed this on Discord and decided to move ahead with preserving the old behavior for now. This seems like the same, or a closely-related, issue as #15510, so we can follow-up on resolving the header-rendering mismatch separately. I added some notes there (#15510 (comment)) from looking into it today too.
Member
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. Perfect. Thank you for looking into it so carefully! Let's merge :) |
||||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -655,6 +655,22 @@ impl<'r> RenderableSnippet<'r> { | |
| .as_source_code() | ||
| .slice(TextRange::new(snippet_start, snippet_end)); | ||
|
|
||
| // Strip the BOM from the beginning of the snippet, if present. Doing this here saves us the | ||
| // trouble of updating the annotation ranges in `replace_unprintable`, and also allows us to | ||
| // check that the BOM is at the very beginning of the file, not just the beginning of the | ||
| // snippet. | ||
| const BOM: char = '\u{feff}'; | ||
| let bom_len = BOM.text_len(); | ||
| let (snippet, snippet_start) = | ||
| if snippet_start == TextSize::default() && snippet.starts_with(BOM) { | ||
|
||
| ( | ||
| &snippet[bom_len.to_usize()..], | ||
| snippet_start + TextSize::new(bom_len.to_u32()), | ||
| ) | ||
| } else { | ||
| (snippet, snippet_start) | ||
| }; | ||
|
|
||
| let annotations = anns | ||
| .iter() | ||
| .map(|ann| RenderableAnnotation::new(snippet_start, ann)) | ||
|
|
@@ -1000,7 +1016,12 @@ fn replace_unprintable<'r>( | |
| let mut last_end = 0; | ||
| let mut result = String::new(); | ||
| for (index, c) in source.char_indices() { | ||
| if let Some(printable) = unprintable_replacement(c) { | ||
| // normalize `\r` line endings but don't double `\r\n` | ||
| if c == '\r' && !matches!(source.get(index + 1..index + 2), Some("\n")) { | ||
|
||
| result.push_str(&source[last_end..index]); | ||
| result.push('\n'); | ||
| last_end = index + 1; | ||
| } else if let Some(printable) = unprintable_replacement(c) { | ||
| result.push_str(&source[last_end..index]); | ||
|
|
||
| let len = printable.text_len().to_u32(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd find a comment what's happening here useful :) Together with a comment that this is another upstream divergence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah definitely makes sense to put the comment here, rather than on the test!