diff options
author | Josh Mcguigan <[email protected]> | 2021-03-07 00:56:07 +0000 |
---|---|---|
committer | Josh Mcguigan <[email protected]> | 2021-03-12 21:36:13 +0000 |
commit | 53bb46fa853bee99f673a0ed0a53798c46847d99 (patch) | |
tree | d692b9f6255109c88e3805408be3bf6dd5c8ec76 /crates/ide_completion/src/render | |
parent | 437527b22612a17024751c78f69715e625bf6a96 (diff) |
show function params in completion detail
Diffstat (limited to 'crates/ide_completion/src/render')
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index f4dabe3d1..e154d6302 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use hir::{HasSource, HirDisplay, Type}; | 3 | use hir::{HasSource, HirDisplay, Type}; |
4 | use ide_db::SymbolKind; | 4 | use ide_db::SymbolKind; |
5 | use itertools::Itertools; | ||
5 | use syntax::ast::Fn; | 6 | use syntax::ast::Fn; |
6 | 7 | ||
7 | use crate::{ | 8 | use crate::{ |
@@ -59,8 +60,34 @@ impl<'a> FunctionRender<'a> { | |||
59 | } | 60 | } |
60 | 61 | ||
61 | fn detail(&self) -> String { | 62 | fn detail(&self) -> String { |
62 | let ty = self.func.ret_type(self.ctx.db()); | 63 | let params = if let Some(self_param) = self.func.self_param(self.ctx.db()) { |
63 | format!("-> {}", ty.display(self.ctx.db())) | 64 | let params = self |
65 | .func | ||
66 | .assoc_fn_params(self.ctx.db()) | ||
67 | .into_iter() | ||
68 | .skip(1) // skip the self param because we are manually handling that | ||
69 | .map(|p| p.ty().display(self.ctx.db()).to_string()); | ||
70 | |||
71 | std::iter::once(self_param.display(self.ctx.db()).to_owned()).chain(params).join(", ") | ||
72 | } else { | ||
73 | let params = self | ||
74 | .func | ||
75 | .assoc_fn_params(self.ctx.db()) | ||
76 | .into_iter() | ||
77 | .map(|p| p.ty().display(self.ctx.db()).to_string()) | ||
78 | .join(", "); | ||
79 | params | ||
80 | }; | ||
81 | |||
82 | 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 | |||
90 | format!("fn({}){}", params, ret) | ||
64 | } | 91 | } |
65 | 92 | ||
66 | fn add_arg(&self, arg: &str, ty: &Type) -> String { | 93 | fn add_arg(&self, arg: &str, ty: &Type) -> String { |