[ty] Fix a few more diagnostic differences from Ruff (#19806)

## Summary

Fixes the remaining range reporting differences between the `ruff_db`
diagnostic rendering and Ruff's existing rendering, as noted in
https://github.com/astral-sh/ruff/pull/19415#issuecomment-3160525595.

This PR is structured as a series of three pairs. The first commit in
each pair adds a test showing the previous behavior, followed by a fix
and the updated snapshot. It's quite a small PR, but that might be
helpful just for the contrast.

You can also look at [this
range](052e656c6c..c3ea51030d)
of commits from #19415 to see the impact on real Ruff diagnostics. I
spun these commits out of that PR.

## Test Plan

New `ruff_db` tests
This commit is contained in:
Brent Westbrook 2025-08-08 11:31:19 -04:00 committed by GitHub
parent 50e1ecc086
commit 8199154d54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 116 additions and 3 deletions

View file

@ -1273,13 +1273,20 @@ fn format_header<'a>(
..
} = item
{
if main_range >= range.0 && main_range < range.1 + max(*end_line as usize, 1) {
// At the very end of the `main_range`, report the location as the first character
// in the next line instead of falling back to the default location of `1:1`. This
// is another divergence from upstream.
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);
break;
}
}
}