fix: Fix don't drop param completions when fully typing out a pattern

This commit is contained in:
Lukas Wirth 2022-01-12 12:36:46 +01:00
parent a3393c9a57
commit 314b199e3c
2 changed files with 23 additions and 3 deletions

View file

@ -83,9 +83,15 @@ fn remove_duplicated(
let whole_param = param.syntax().text().to_string();
file_params.remove(&whole_param);
if let Some(pattern) = param.pat() {
let binding = pattern.syntax().text().to_string();
file_params.retain(|_, v| v != &binding);
match param.pat() {
// remove suggestions for patterns that already exist
// if the type is missing we are checking the current param to be completed
// in which case this would find itself removing the suggestions due to itself
Some(pattern) if param.ty().is_some() => {
let binding = pattern.syntax().text().to_string();
file_params.retain(|_, v| v != &binding);
}
_ => (),
}
})
}

View file

@ -368,3 +368,17 @@ fn foo() {
"#]],
)
}
#[test]
fn completes_fully_equal() {
check_empty(
r#"
fn foo(bar: u32) {}
fn bar(bar$0) {}
"#,
expect![[r#"
bn bar: u32
kw mut
"#]],
)
}