Replace Display by a pretty printing trait for Ty
This allows removing the names from Adt and FnDef (and more later), as a first step towards aligning more with chalk's Ty :)
This commit is contained in:
committed by
Florian Diebold
parent
eb4d6cf25f
commit
c5ee60e05b
@@ -1,7 +1,7 @@
|
||||
//! This modules takes care of rendering various defenitions as completion items.
|
||||
use join_to_string::join;
|
||||
use test_utils::tested_by;
|
||||
use hir::{Docs, PerNs, Resolution};
|
||||
use hir::{Docs, PerNs, Resolution, HirDisplay};
|
||||
use ra_syntax::ast::NameOwner;
|
||||
|
||||
use crate::completion::{
|
||||
@@ -22,7 +22,7 @@ impl Completions {
|
||||
field.name(ctx.db).to_string(),
|
||||
)
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(field.ty(ctx.db).subst(substs).to_string())
|
||||
.detail(field.ty(ctx.db).subst(substs).display(ctx.db).to_string())
|
||||
.set_documentation(field.docs(ctx.db))
|
||||
.add_to(self);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ impl Completions {
|
||||
pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) {
|
||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string())
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(ty.to_string())
|
||||
.detail(ty.display(ctx.db).to_string())
|
||||
.add_to(self);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,10 @@ impl Completions {
|
||||
None => return,
|
||||
};
|
||||
let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db));
|
||||
let detail = join(detail_types).separator(", ").surround_with("(", ")").to_string();
|
||||
let detail = join(detail_types.map(|t| t.display(ctx.db).to_string()))
|
||||
.separator(", ")
|
||||
.surround_with("(", ")")
|
||||
.to_string();
|
||||
|
||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string())
|
||||
.kind(CompletionItemKind::EnumVariant)
|
||||
|
||||
@@ -3,6 +3,7 @@ use ra_syntax::{
|
||||
AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner},
|
||||
algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},
|
||||
};
|
||||
use hir::HirDisplay;
|
||||
|
||||
use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};
|
||||
|
||||
@@ -134,9 +135,9 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
|
||||
let infer = function.infer(db);
|
||||
let source_map = function.body_source_map(db);
|
||||
if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) {
|
||||
Some(infer[expr].to_string())
|
||||
Some(infer[expr].display(db).to_string())
|
||||
} else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) {
|
||||
Some(infer[pat].to_string())
|
||||
Some(infer[pat].display(db).to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user