inline parameters for a function description #6002

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
Benjamin Coenen 2020-09-15 17:14:48 +02:00
parent 7ba578ab14
commit 2e91159ced
2 changed files with 29 additions and 1 deletions

View File

@ -730,4 +730,26 @@ fn f() {}
expect![[""]],
);
}
#[test]
fn completes_function() {
check(
r#"
fn foo(
a: i32,
b: i32
) {
}
fn main() {
fo<|>
}
"#,
expect![[r#"
fn foo() fn foo(a: i32, b: i32)
fn main() fn main()
"#]],
);
}
}

View File

@ -41,7 +41,13 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String {
format_to!(buf, "{}", type_params);
}
if let Some(param_list) = node.param_list() {
format_to!(buf, "{}", param_list);
let mut params = match param_list.self_param() {
Some(self_param) => vec![self_param.to_string()],
None => vec![],
};
params.extend(param_list.params().map(|param| param.to_string()));
// Useful to inline parameters
format_to!(buf, "({})", params.join(", "));
}
if let Some(ret_type) = node.ret_type() {
if ret_type.ty().is_some() {