diff options
author | Josh Mcguigan <[email protected]> | 2021-03-12 21:46:40 +0000 |
---|---|---|
committer | Josh Mcguigan <[email protected]> | 2021-03-12 21:46:40 +0000 |
commit | d5f0f58e6330efd8200f93a6904caafc600a904e (patch) | |
tree | 4edb9751d70b50892c83d1cb7186b39b025bd7ba /crates/ide_completion/src/render | |
parent | 53bb46fa853bee99f673a0ed0a53798c46847d99 (diff) |
add params_display and ty_display
Diffstat (limited to 'crates/ide_completion/src/render')
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 26 |
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 { |