mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
show function params in completion detail
This commit is contained in:
parent
437527b226
commit
53bb46fa85
8 changed files with 155 additions and 82 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue