6008: inline parameters for a function description r=jonas-schievink a=bnjjj

close #6002 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
bors[bot] 2020-09-15 16:18:30 +00:00 committed by GitHub
commit 37f3b9ca2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -730,4 +730,26 @@ fn f() {}
expect![[""]], 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,14 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String {
format_to!(buf, "{}", type_params); format_to!(buf, "{}", type_params);
} }
if let Some(param_list) = node.param_list() { if let Some(param_list) = node.param_list() {
format_to!(buf, "{}", param_list); let params: Vec<String> = param_list
.self_param()
.into_iter()
.map(|self_param| self_param.to_string())
.chain(param_list.params().map(|param| param.to_string()))
.collect();
// Useful to inline parameters
format_to!(buf, "({})", params.join(", "));
} }
if let Some(ret_type) = node.ret_type() { if let Some(ret_type) = node.ret_type() {
if ret_type.ty().is_some() { if ret_type.ty().is_some() {