From 2e91159cedcf8e2acd9f2f32523cce582a2b89ea Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:14:48 +0200 Subject: inline parameters for a function description #6002 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- .../ide/src/completion/complete_qualified_path.rs | 22 ++++++++++++++++++++++ crates/ide/src/display.rs | 8 +++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ide/src/completion/complete_qualified_path.rs b/crates/ide/src/completion/complete_qualified_path.rs index 79de50792..00e89f0fd 100644 --- a/crates/ide/src/completion/complete_qualified_path.rs +++ b/crates/ide/src/completion/complete_qualified_path.rs @@ -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() + "#]], + ); + } } diff --git a/crates/ide/src/display.rs b/crates/ide/src/display.rs index 41b5bdc49..5bb065fc1 100644 --- a/crates/ide/src/display.rs +++ b/crates/ide/src/display.rs @@ -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() { -- cgit v1.2.3 From e0f0d93eda8fbcd523187ef29b713acb9a92cb6f Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 15 Sep 2020 18:04:34 +0200 Subject: inline parameters for a function description #6002 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ide/src/display.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/display.rs b/crates/ide/src/display.rs index 5bb065fc1..2484dbbf1 100644 --- a/crates/ide/src/display.rs +++ b/crates/ide/src/display.rs @@ -41,11 +41,12 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String { format_to!(buf, "{}", type_params); } if let Some(param_list) = node.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())); + let params: Vec = 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(", ")); } -- cgit v1.2.3