aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r--crates/ide_completion/src/render/function.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs
index e154d6302..b6b67e7a7 100644
--- a/crates/ide_completion/src/render/function.rs
+++ b/crates/ide_completion/src/render/function.rs
@@ -60,7 +60,19 @@ impl<'a> FunctionRender<'a> {
60 } 60 }
61 61
62 fn detail(&self) -> String { 62 fn detail(&self) -> String {
63 let params = if let Some(self_param) = self.func.self_param(self.ctx.db()) { 63 let ret_ty = self.func.ret_type(self.ctx.db());
64 let ret = if ret_ty.is_unit() {
65 // Omit the return type if it is the unit type
66 String::new()
67 } else {
68 format!(" {}", self.ty_display())
69 };
70
71 format!("fn({}){}", self.params_display(), ret)
72 }
73
74 fn params_display(&self) -> String {
75 if let Some(self_param) = self.func.self_param(self.ctx.db()) {
64 let params = self 76 let params = self
65 .func 77 .func
66 .assoc_fn_params(self.ctx.db()) 78 .assoc_fn_params(self.ctx.db())
@@ -77,17 +89,13 @@ impl<'a> FunctionRender<'a> {
77 .map(|p| p.ty().display(self.ctx.db()).to_string()) 89 .map(|p| p.ty().display(self.ctx.db()).to_string())
78 .join(", "); 90 .join(", ");
79 params 91 params
80 }; 92 }
93 }
81 94
95 fn ty_display(&self) -> String {
82 let ret_ty = self.func.ret_type(self.ctx.db()); 96 let ret_ty = self.func.ret_type(self.ctx.db());
83 let ret = if ret_ty.is_unit() {
84 // Omit the `-> ()` for unit return types
85 String::new()
86 } else {
87 format!(" -> {}", ret_ty.display(self.ctx.db()))
88 };
89 97
90 format!("fn({}){}", params, ret) 98 format!("-> {}", ret_ty.display(self.ctx.db()))
91 } 99 }
92 100
93 fn add_arg(&self, arg: &str, ty: &Type) -> String { 101 fn add_arg(&self, arg: &str, ty: &Type) -> String {