add paramthesis when completing functions

This commit is contained in:
Aleksey Kladov 2018-12-30 12:29:55 +03:00
parent e2bc57e3c8
commit 1ac934eafa
2 changed files with 39 additions and 10 deletions

View file

@ -74,7 +74,7 @@ mod tests {
let z = ();
}
",
"y;x;quux",
r#"y;x;quux "quux($0)""#,
);
}
@ -92,7 +92,7 @@ mod tests {
}
}
",
"b;a;quux",
r#"b;a;quux "quux()$0""#,
);
}
@ -106,7 +106,7 @@ mod tests {
}
}
",
"x;quux",
r#"x;quux "quux()$0""#,
);
}
@ -120,7 +120,7 @@ mod tests {
<|>
}
",
"quux;Foo;Baz",
r#"quux "quux()$0";Foo;Baz"#,
);
}
@ -134,7 +134,7 @@ mod tests {
fn quux() { <|> }
}
",
"quux;Bar",
r#"quux "quux()$0";Bar"#,
);
}
@ -145,12 +145,12 @@ mod tests {
struct Foo;
fn x() -> <|>
",
"Foo;x",
r#"Foo;x "x()$0""#,
)
}
#[test]
fn dont_show_to_completions_for_shadowing() {
fn dont_show_both_completions_for_shadowing() {
check_reference_completion(
r"
fn foo() -> {
@ -161,7 +161,7 @@ mod tests {
}
}
",
"bar;foo",
r#"bar;foo "foo()$0""#,
)
}
@ -169,4 +169,24 @@ mod tests {
fn completes_self_in_methods() {
check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self")
}
#[test]
fn inserts_parens_for_function_calls() {
check_reference_completion(
r"
fn no_args() {}
fn main() { no_<|> }
",
r#"no_args "no_args()$0"
main "main()$0""#,
);
check_reference_completion(
r"
fn with_args(x: i32, y: String) {}
fn main() { with_<|> }
",
r#"main "main()$0"
with_args "with_args($0)""#,
);
}
}

View file

@ -138,9 +138,18 @@ impl Builder {
..
} => CompletionItemKind::Enum,
PerNs {
values: Some(hir::Def::Function(..)),
values: Some(hir::Def::Function(function)),
..
} => CompletionItemKind::Function,
} => {
if let Some(sig_info) = function.signature_info(db) {
if sig_info.params.is_empty() {
self.snippet = Some(format!("{}()$0", self.label));
} else {
self.snippet = Some(format!("{}($0)", self.label));
}
}
CompletionItemKind::Function
}
_ => return self,
};
self.kind = Some(kind);