From 53bb46fa853bee99f673a0ed0a53798c46847d99 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 6 Mar 2021 16:56:07 -0800 Subject: show function params in completion detail --- crates/ide_completion/src/render/function.rs | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'crates/ide_completion/src/render') 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 @@ use hir::{HasSource, HirDisplay, Type}; use ide_db::SymbolKind; +use itertools::Itertools; use syntax::ast::Fn; use crate::{ @@ -59,8 +60,34 @@ impl<'a> FunctionRender<'a> { } fn detail(&self) -> String { - let ty = self.func.ret_type(self.ctx.db()); - format!("-> {}", ty.display(self.ctx.db())) + let params = if let Some(self_param) = self.func.self_param(self.ctx.db()) { + let params = self + .func + .assoc_fn_params(self.ctx.db()) + .into_iter() + .skip(1) // skip the self param because we are manually handling that + .map(|p| p.ty().display(self.ctx.db()).to_string()); + + std::iter::once(self_param.display(self.ctx.db()).to_owned()).chain(params).join(", ") + } else { + let params = self + .func + .assoc_fn_params(self.ctx.db()) + .into_iter() + .map(|p| p.ty().display(self.ctx.db()).to_string()) + .join(", "); + params + }; + + let ret_ty = self.func.ret_type(self.ctx.db()); + let ret = if ret_ty.is_unit() { + // Omit the `-> ()` for unit return types + String::new() + } else { + format!(" -> {}", ret_ty.display(self.ctx.db())) + }; + + format!("fn({}){}", params, ret) } fn add_arg(&self, arg: &str, ty: &Type) -> String { -- cgit v1.2.3