From 8221450cbcf2d68840322810c99cc4fafcb2ad11 Mon Sep 17 00:00:00 2001 From: Douglas Creager Date: Wed, 8 Oct 2025 14:18:03 -0400 Subject: [PATCH] [ty_test] Store HoverAssertion.column as zero-based MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- crates/ty_test/src/assertion.rs | 9 +++------ crates/ty_test/src/hover.rs | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/ty_test/src/assertion.rs b/crates/ty_test/src/assertion.rs index 7ec39482f8..4bd0637347 100644 --- a/crates/ty_test/src/assertion.rs +++ b/crates/ty_test/src/assertion.rs @@ -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, diff --git a/crates/ty_test/src/hover.rs b/crates/ty_test/src/hover.rs index 43aa67e6f3..a037162a07 100644 --- a/crates/ty_test/src/hover.rs +++ b/crates/ty_test/src/hover.rs @@ -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 {