aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/render')
-rw-r--r--crates/ide_completion/src/render/function.rs31
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
3use hir::{HasSource, HirDisplay, Type}; 3use hir::{HasSource, HirDisplay, Type};
4use ide_db::SymbolKind; 4use ide_db::SymbolKind;
5use itertools::Itertools;
5use syntax::ast::Fn; 6use syntax::ast::Fn;
6 7
7use crate::{ 8use 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 {