add params_display and ty_display

This commit is contained in:
Josh Mcguigan 2021-03-12 13:46:40 -08:00
parent 53bb46fa85
commit d5f0f58e63

View File

@ -60,7 +60,19 @@ fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
}
fn detail(&self) -> String {
let params = if let Some(self_param) = self.func.self_param(self.ctx.db()) {
let ret_ty = self.func.ret_type(self.ctx.db());
let ret = if ret_ty.is_unit() {
// Omit the return type if it is the unit type
String::new()
} else {
format!(" {}", self.ty_display())
};
format!("fn({}){}", self.params_display(), ret)
}
fn params_display(&self) -> String {
if let Some(self_param) = self.func.self_param(self.ctx.db()) {
let params = self
.func
.assoc_fn_params(self.ctx.db())
@ -77,17 +89,13 @@ fn detail(&self) -> String {
.map(|p| p.ty().display(self.ctx.db()).to_string())
.join(", ");
params
};
}
}
fn ty_display(&self) -> String {
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)
format!("-> {}", ret_ty.display(self.ctx.db()))
}
fn add_arg(&self, arg: &str, ty: &Type) -> String {