aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-03-14 21:03:39 +0000
committerFlorian Diebold <[email protected]>2019-03-16 15:36:59 +0000
commitc5ee60e05b1fafe20f56b21cfab30e7b80cb9d42 (patch)
tree9a6e1f6aeb348ac5c6c5e0f89cd791a9430550f2 /crates/ra_ide_api
parenteb4d6cf25f9ba886f4aa8ee46149af2807baae7f (diff)
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 :)
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs11
-rw-r--r--crates/ra_ide_api/src/hover.rs5
2 files changed, 10 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 71003104b..28c8f83ab 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -1,7 +1,7 @@
1//! This modules takes care of rendering various defenitions as completion items. 1//! This modules takes care of rendering various defenitions as completion items.
2use join_to_string::join; 2use join_to_string::join;
3use test_utils::tested_by; 3use test_utils::tested_by;
4use hir::{Docs, PerNs, Resolution}; 4use hir::{Docs, PerNs, Resolution, HirDisplay};
5use ra_syntax::ast::NameOwner; 5use ra_syntax::ast::NameOwner;
6 6
7use crate::completion::{ 7use crate::completion::{
@@ -22,7 +22,7 @@ impl Completions {
22 field.name(ctx.db).to_string(), 22 field.name(ctx.db).to_string(),
23 ) 23 )
24 .kind(CompletionItemKind::Field) 24 .kind(CompletionItemKind::Field)
25 .detail(field.ty(ctx.db).subst(substs).to_string()) 25 .detail(field.ty(ctx.db).subst(substs).display(ctx.db).to_string())
26 .set_documentation(field.docs(ctx.db)) 26 .set_documentation(field.docs(ctx.db))
27 .add_to(self); 27 .add_to(self);
28 } 28 }
@@ -30,7 +30,7 @@ impl Completions {
30 pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) { 30 pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) {
31 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string()) 31 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string())
32 .kind(CompletionItemKind::Field) 32 .kind(CompletionItemKind::Field)
33 .detail(ty.to_string()) 33 .detail(ty.display(ctx.db).to_string())
34 .add_to(self); 34 .add_to(self);
35 } 35 }
36 36
@@ -154,7 +154,10 @@ impl Completions {
154 None => return, 154 None => return,
155 }; 155 };
156 let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); 156 let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db));
157 let detail = join(detail_types).separator(", ").surround_with("(", ")").to_string(); 157 let detail = join(detail_types.map(|t| t.display(ctx.db).to_string()))
158 .separator(", ")
159 .surround_with("(", ")")
160 .to_string();
158 161
159 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) 162 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string())
160 .kind(CompletionItemKind::EnumVariant) 163 .kind(CompletionItemKind::EnumVariant)
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 66a625c6c..f6a83dd93 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -3,6 +3,7 @@ use ra_syntax::{
3 AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner}, 3 AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner},
4 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, 4 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},
5}; 5};
6use hir::HirDisplay;
6 7
7use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; 8use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};
8 9
@@ -134,9 +135,9 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
134 let infer = function.infer(db); 135 let infer = function.infer(db);
135 let source_map = function.body_source_map(db); 136 let source_map = function.body_source_map(db);
136 if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) { 137 if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) {
137 Some(infer[expr].to_string()) 138 Some(infer[expr].display(db).to_string())
138 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) { 139 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) {
139 Some(infer[pat].to_string()) 140 Some(infer[pat].display(db).to_string())
140 } else { 141 } else {
141 None 142 None
142 } 143 }