mirror of https://github.com/astral-sh/ruff
[ty_test] Use let-else pattern in generate_hover_outputs
Replace nested if-let blocks with let-else + continue to reduce indentation and improve readability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
19600ecd51
commit
ab261360e4
|
|
@ -86,26 +86,31 @@ pub(crate) fn generate_hover_outputs(
|
||||||
|
|
||||||
// Look for hover assertions in this line's assertions
|
// Look for hover assertions in this line's assertions
|
||||||
for assertion in line_assertions.iter() {
|
for assertion in line_assertions.iter() {
|
||||||
if let crate::assertion::UnparsedAssertion::Hover(hover_text) = assertion {
|
let crate::assertion::UnparsedAssertion::Hover(hover_text) = assertion else {
|
||||||
// Find the down arrow position in the comment text to determine the column
|
continue;
|
||||||
if let Some(arrow_position) = hover_text.find('↓') {
|
};
|
||||||
// Get the start offset of the target line
|
|
||||||
let target_line_start = lines.line_start(target_line, &source);
|
|
||||||
|
|
||||||
// Calculate the hover position: start of target line + arrow column (0-indexed)
|
// Find the down arrow position in the comment text to determine the column
|
||||||
let hover_offset =
|
let Some(arrow_position) = hover_text.find('↓') else {
|
||||||
target_line_start + TextSize::try_from(arrow_position).unwrap();
|
// No down arrow - skip this hover assertion (will be caught as error by matcher)
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
// Get the inferred type at that position
|
// Get the start offset of the target line
|
||||||
if let Some(inferred_type) = infer_type_at_position(db, file, hover_offset) {
|
let target_line_start = lines.line_start(target_line, &source);
|
||||||
hover_outputs.push(matcher::CheckOutput::Hover {
|
|
||||||
offset: hover_offset,
|
// Calculate the hover position: start of target line + arrow column (0-indexed)
|
||||||
inferred_type,
|
let hover_offset = target_line_start + TextSize::try_from(arrow_position).unwrap();
|
||||||
});
|
|
||||||
}
|
// Get the inferred type at that position
|
||||||
}
|
let Some(inferred_type) = infer_type_at_position(db, file, hover_offset) else {
|
||||||
// If no down arrow, skip this hover assertion (will be caught as error by matcher)
|
continue;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
hover_outputs.push(matcher::CheckOutput::Hover {
|
||||||
|
offset: hover_offset,
|
||||||
|
inferred_type,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue