[ty_test] Simplify column calculation using line_column

Instead of manually calculating character offsets, use line_column()
which does all the work for us:

1. Find the byte offset of the arrow in the comment text
2. Add that to the comment's TextRange to get the arrow's absolute position
3. Call line_column() on that position to get the character column

This is much simpler and lets line_column handle all the UTF-8/UTF-32
conversion complexity.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Douglas Creager 2025-10-08 14:36:24 -04:00
parent c574dff6b0
commit 6d1c549c4e
1 changed files with 10 additions and 9 deletions

View File

@ -397,18 +397,19 @@ impl<'a> HoverAssertion<'a> {
return Err(HoverAssertionParseError::EmptyType);
}
// Find the down arrow position within the comment text (as character offset)
let arrow_char_offset_in_comment = full_comment
.chars()
.position(|c| c == '↓')
// Find the down arrow position within the comment text (as byte offset)
let arrow_byte_offset_in_comment = full_comment
.find('↓')
.ok_or(HoverAssertionParseError::MissingDownArrow)?;
// Calculate the column within the comment's line
// First, get the line and column of the comment's start
let comment_line_col = line_index.line_column(comment_range.start(), source);
// Calculate the TextSize position of the down arrow in the source file
let arrow_position = comment_range.start() + TextSize::try_from(arrow_byte_offset_in_comment).unwrap();
// The hover column is the comment's column plus the arrow's character offset within the comment
let column = comment_line_col.column.to_zero_indexed() + arrow_char_offset_in_comment;
// Get the line and character column of the down arrow
let arrow_line_col = line_index.line_column(arrow_position, source);
// Store the character column (which line_column already computed for us)
let column = arrow_line_col.column.to_zero_indexed();
Ok(Self {
column,