diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index e59d60e802908..0d3330b2cc5ed 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -1411,6 +1411,13 @@ fn add_argument_completions<'db>( let mut in_arguments = false; for node in cursor.covering_node.ancestors() { match node { + // Do not suggest argument completions in value positions for + // keyword arguments + ast::AnyNodeRef::Keyword(kw) => { + if kw.value.range().contains_range(cursor.range) { + return; + } + } ast::AnyNodeRef::Arguments(_) => { in_arguments = true; } @@ -8733,6 +8740,28 @@ re.match('', '', fla ); } + #[test] + fn call_keyword_argument_at_value() { + let builder = completion_test_builder( + "\ +def bar(y_true,y_pred): ... + +y_true = 1 +y_pred = 2 + +bar(y_true=y +", + ); + + assert_snapshot!( + builder.skip_keywords().skip_builtins().skip_auto_import().build().snapshot(), + @r###" + y_pred + y_true + "### + ); + } + // Ideally, we should favour completions that are definitely raisable // here. However, doing so would require `exception_ty` to fall back to // token matching when AST-matching fails, making the function signficantly