Skip to content

Commit 9622285

Browse files
authored
[ty] Autocomplete arguments if in arguments node (#24167)
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary Addresses [this comment](astral-sh/ty#3087 (comment)). Fixes astral-sh/ty#3087. I initially did the same ancestor walking check in both places but then I tried to come up with another way that does not iterate multiple times. Since in `add_argument_completions` we are already iterating over node ancestors of the node the cursor is in, we can determine if cursor is in an arguments node. So I did that instead of duplicating the `cursor.covering_node.ancestors() ...` code. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan Added the test case that would panic in debug build without this fix. <!-- How was it tested? -->
1 parent d812662 commit 9622285

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

crates/ty_ide/src/completion.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,10 +1397,14 @@ fn add_argument_completions<'db>(
13971397
cursor: &ContextCursor<'_>,
13981398
completions: &mut Completions<'db>,
13991399
) {
1400+
let mut in_arguments = false;
14001401
for node in cursor.covering_node.ancestors() {
14011402
match node {
1402-
ast::AnyNodeRef::ExprCall(call) => {
1403-
if call.arguments.range().contains_range(cursor.range) {
1403+
ast::AnyNodeRef::Arguments(_) => {
1404+
in_arguments = true;
1405+
}
1406+
ast::AnyNodeRef::ExprCall(_) => {
1407+
if in_arguments {
14041408
add_function_arg_completions(db, model.file(), cursor, completions);
14051409
}
14061410
return;
@@ -5465,6 +5469,21 @@ def test_point(p2: Point):
54655469
builder.build().contains("orthogonal_direction");
54665470
}
54675471

5472+
// https://github.com/astral-sh/ty/issues/3087
5473+
#[test]
5474+
fn no_panic_argument_completion_before_paren() {
5475+
let builder = completion_test_builder(
5476+
r#"
5477+
list[int]<CURSOR>()
5478+
"#,
5479+
);
5480+
5481+
assert_snapshot!(
5482+
builder.skip_keywords().skip_builtins().skip_auto_import().build().snapshot(),
5483+
@"<No completions found after filtering out completions>",
5484+
);
5485+
}
5486+
54685487
#[test]
54695488
fn from_import1() {
54705489
let builder = completion_test_builder(

0 commit comments

Comments
 (0)