aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs11
-rw-r--r--crates/ra_hir/src/docs.rs2
-rw-r--r--crates/ra_hir/src/generics.rs2
-rw-r--r--crates/ra_hir/src/type_alias.rs2
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs5
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs20
-rw-r--r--crates/ra_ide_api/src/hover.rs18
7 files changed, 22 insertions, 38 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index a8a0875e0..20a8d7d80 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -932,12 +932,19 @@ pub struct TypeAlias {
932 pub(crate) id: TypeAliasId, 932 pub(crate) id: TypeAliasId,
933} 933}
934 934
935impl HasSource for TypeAlias {
936 type Ast = TreeArc<ast::TypeAliasDef>;
937 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> {
938 self.id.source(db).into()
939 }
940}
941
935impl TypeAlias { 942impl TypeAlias {
936 pub fn source( 943 pub fn source(
937 self, 944 self,
938 db: &(impl DefDatabase + AstDatabase), 945 db: &(impl DefDatabase + AstDatabase),
939 ) -> (HirFileId, TreeArc<ast::TypeAliasDef>) { 946 ) -> Source<TreeArc<ast::TypeAliasDef>> {
940 self.id.source(db) 947 self.id.source(db).into()
941 } 948 }
942 949
943 pub fn module(self, db: &impl DefDatabase) -> Module { 950 pub fn module(self, db: &impl DefDatabase) -> Module {
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs
index 86ca981f4..1c6b4f205 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -84,7 +84,7 @@ pub(crate) fn documentation_query(
84 DocDef::Function(it) => docs_from_ast(&*it.source(db).ast), 84 DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
85 DocDef::Union(it) => docs_from_ast(&*it.source(db).1), 85 DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), 86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), 87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
88 DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1), 88 DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
89 } 89 }
90} 90}
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index fcccd67c8..b7e255c17 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -81,7 +81,7 @@ impl GenericParams {
81 }); 81 });
82 generics.fill(&*it.source(db).1, start + 1); 82 generics.fill(&*it.source(db).1, start + 1);
83 } 83 }
84 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).1, start), 84 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
85 GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start), 85 GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
86 } 86 }
87 87
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs
index 970468e3c..c449d7346 100644
--- a/crates/ra_hir/src/type_alias.rs
+++ b/crates/ra_hir/src/type_alias.rs
@@ -8,6 +8,6 @@ pub(crate) fn type_alias_ref_query(
8 db: &(impl DefDatabase + AstDatabase), 8 db: &(impl DefDatabase + AstDatabase),
9 typ: TypeAlias, 9 typ: TypeAlias,
10) -> Arc<TypeRef> { 10) -> Arc<TypeRef> {
11 let (_, node) = typ.source(db); 11 let node = typ.source(db).ast;
12 Arc::new(TypeRef::from_ast_opt(node.type_ref())) 12 Arc::new(TypeRef::from_ast_opt(node.type_ref()))
13} 13}
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 8c4d7127b..495899262 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -141,13 +141,12 @@ impl Completions {
141 } 141 }
142 142
143 pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { 143 pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
144 let (_file_id, type_def) = type_alias.source(ctx.db); 144 let type_def = type_alias.source(ctx.db).ast;
145 let name = match type_def.name() { 145 let name = match type_def.name() {
146 Some(name) => name, 146 Some(name) => name,
147 _ => return, 147 _ => return,
148 }; 148 };
149 let (_, ast_node) = type_alias.source(ctx.db); 149 let detail = type_label(&type_def);
150 let detail = type_label(&ast_node);
151 150
152 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) 151 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
153 .kind(CompletionItemKind::TypeAlias) 152 .kind(CompletionItemKind::TypeAlias)
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index a036a3b36..19a64f300 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -232,15 +232,7 @@ impl NavigationTarget {
232 node.short_label(), 232 node.short_label(),
233 ) 233 )
234 } 234 }
235 hir::ModuleDef::TypeAlias(e) => { 235 hir::ModuleDef::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
236 let (file_id, node) = e.source(db);
237 NavigationTarget::from_named(
238 file_id.original_file(db),
239 &*node,
240 node.doc_comment_text(),
241 node.short_label(),
242 )
243 }
244 hir::ModuleDef::BuiltinType(..) => { 236 hir::ModuleDef::BuiltinType(..) => {
245 return None; 237 return None;
246 } 238 }
@@ -267,15 +259,7 @@ impl NavigationTarget {
267 match impl_item { 259 match impl_item {
268 ImplItem::Method(it) => NavigationTarget::from_function(db, it), 260 ImplItem::Method(it) => NavigationTarget::from_function(db, it),
269 ImplItem::Const(it) => NavigationTarget::from_def_source(db, it), 261 ImplItem::Const(it) => NavigationTarget::from_def_source(db, it),
270 ImplItem::TypeAlias(a) => { 262 ImplItem::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
271 let (file_id, node) = a.source(db);
272 NavigationTarget::from_named(
273 file_id.original_file(db),
274 &*node,
275 node.doc_comment_text(),
276 node.short_label(),
277 )
278 }
279 } 263 }
280 } 264 }
281 265
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 0f68cacca..c4826e515 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -107,14 +107,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
107 res.extend(hover_text(it.doc_comment_text(), it.short_label())); 107 res.extend(hover_text(it.doc_comment_text(), it.short_label()));
108 } 108 }
109 } 109 }
110 Some(AssocItem(it)) => match it { 110 Some(AssocItem(it)) => res.extend(match it {
111 hir::ImplItem::Method(it) => res.extend(from_def_source(db, it)), 111 hir::ImplItem::Method(it) => from_def_source(db, it),
112 hir::ImplItem::Const(it) => res.extend(from_def_source(db, it)), 112 hir::ImplItem::Const(it) => from_def_source(db, it),
113 hir::ImplItem::TypeAlias(it) => { 113 hir::ImplItem::TypeAlias(it) => from_def_source(db, it),
114 let it = it.source(db).1; 114 }),
115 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
116 }
117 },
118 Some(Def(it)) => { 115 Some(Def(it)) => {
119 match it { 116 match it {
120 hir::ModuleDef::Module(it) => { 117 hir::ModuleDef::Module(it) => {
@@ -137,10 +134,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
137 let it = it.source(db).1; 134 let it = it.source(db).1;
138 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 135 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
139 } 136 }
140 hir::ModuleDef::TypeAlias(it) => { 137 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
141 let it = it.source(db).1;
142 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
143 }
144 hir::ModuleDef::BuiltinType(_) => { 138 hir::ModuleDef::BuiltinType(_) => {
145 // FIXME: hover for builtin Type ? 139 // FIXME: hover for builtin Type ?
146 } 140 }