]> git.lizzy.rs Git - rust.git/commitdiff
inline parameters for a function description #6002
authorBenjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Tue, 15 Sep 2020 15:14:48 +0000 (17:14 +0200)
committerBenjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Tue, 15 Sep 2020 15:15:33 +0000 (17:15 +0200)
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
crates/ide/src/completion/complete_qualified_path.rs
crates/ide/src/display.rs

index 79de50792782d237d33afe90be5a24df1e8c2fe2..00e89f0fdf263799680338fbd877360243e12f7d 100644 (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()
+            "#]],
+        );
+    }
 }
index 41b5bdc490c086859f74f607a07793b82319a36c..5bb065fc163162d18c09d46438dc3cd39557d76b 100644 (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() {