mirror of https://github.com/astral-sh/ruff
[ty_test] Store HoverAssertion.column as zero-based
Change the column field in HoverAssertion from OneIndexed to usize, storing it as a zero-based index. This matches how it's used and eliminates unnecessary conversions between zero-based and one-based indexing. The arrow position from find() is already zero-based, and TextSize uses zero-based offsets, so this is more natural. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
93db8833ef
commit
8221450cbc
|
|
@ -363,9 +363,9 @@ impl std::fmt::Display for ErrorAssertion<'_> {
|
|||
/// A parsed and validated `# hover:` assertion comment.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct HoverAssertion<'a> {
|
||||
/// The column where the down arrow appears in the assertion comment.
|
||||
/// The zero-based column where the down arrow appears in the assertion comment.
|
||||
/// This indicates the position in the next line where we should hover.
|
||||
pub(crate) column: OneIndexed,
|
||||
pub(crate) column: usize,
|
||||
|
||||
/// The expected type at the hover position.
|
||||
pub(crate) expected_type: &'a str,
|
||||
|
|
@ -381,13 +381,10 @@ impl<'a> HoverAssertion<'a> {
|
|||
}
|
||||
|
||||
// Find the down arrow position in the full comment to determine the column
|
||||
let arrow_position = full_comment
|
||||
let column = full_comment
|
||||
.find('↓')
|
||||
.ok_or(HoverAssertionParseError::MissingDownArrow)?;
|
||||
|
||||
// Column is 1-indexed, and the arrow position is 0-indexed
|
||||
let column = OneIndexed::from_zero_indexed(arrow_position);
|
||||
|
||||
Ok(Self {
|
||||
column,
|
||||
expected_type,
|
||||
|
|
|
|||
|
|
@ -110,9 +110,7 @@ pub(crate) fn generate_hover_outputs(
|
|||
let target_line_start = lines.line_start(target_line, &source);
|
||||
|
||||
// Calculate the hover position from the column in the parsed assertion
|
||||
// Column is 1-indexed, so convert to 0-indexed for TextSize
|
||||
let hover_offset =
|
||||
target_line_start + TextSize::try_from(hover.column.get() - 1).unwrap();
|
||||
let hover_offset = target_line_start + TextSize::try_from(hover.column).unwrap();
|
||||
|
||||
// Get the inferred type at that position
|
||||
let Some(inferred_type) = infer_type_at_position(db, file, hover_offset) else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue