aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/add_missing_impl_members.rs2
-rw-r--r--crates/ra_hir/src/code_model.rs21
-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/traits.rs10
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs20
-rw-r--r--crates/ra_ide_api/src/hover.rs10
7 files changed, 28 insertions, 39 deletions
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs
index 23c01e747..046f53a8c 100644
--- a/crates/ra_assists/src/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/add_missing_impl_members.rs
@@ -110,7 +110,7 @@ fn resolve_target_trait_def(
110 impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?.path()?; 110 impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?.path()?;
111 111
112 match analyzer.resolve_path(db, &ast_path) { 112 match analyzer.resolve_path(db, &ast_path) {
113 Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).1), 113 Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).ast),
114 _ => None, 114 _ => None,
115 } 115 }
116} 116}
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 20a8d7d80..0a750b590 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -528,6 +528,13 @@ pub struct EnumVariant {
528 pub(crate) id: EnumVariantId, 528 pub(crate) id: EnumVariantId,
529} 529}
530 530
531impl HasSource for EnumVariant {
532 type Ast = TreeArc<ast::EnumVariant>;
533 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumVariant>> {
534 self.source_impl(db)
535 }
536}
537
531impl EnumVariant { 538impl EnumVariant {
532 pub fn source( 539 pub fn source(
533 &self, 540 &self,
@@ -886,12 +893,16 @@ pub struct Trait {
886 pub(crate) id: TraitId, 893 pub(crate) id: TraitId,
887} 894}
888 895
896impl HasSource for Trait {
897 type Ast = TreeArc<ast::TraitDef>;
898 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
899 self.id.source(db).into()
900 }
901}
902
889impl Trait { 903impl Trait {
890 pub fn source( 904 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
891 self, 905 self.id.source(db).into()
892 db: &(impl DefDatabase + AstDatabase),
893 ) -> (HirFileId, TreeArc<ast::TraitDef>) {
894 self.id.source(db)
895 } 906 }
896 907
897 pub fn module(self, db: &impl DefDatabase) -> Module { 908 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 1c6b4f205..0cb0c0db8 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -83,7 +83,7 @@ pub(crate) fn documentation_query(
83 DocDef::Const(it) => docs_from_ast(&*it.source(db).ast), 83 DocDef::Const(it) => docs_from_ast(&*it.source(db).ast),
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).ast),
87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast), 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 }
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index b7e255c17..08d711754 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -79,7 +79,7 @@ impl GenericParams {
79 name: Name::self_type(), 79 name: Name::self_type(),
80 default: None, 80 default: None,
81 }); 81 });
82 generics.fill(&*it.source(db).1, start + 1); 82 generics.fill(&*it.source(db).ast, start + 1);
83 } 83 }
84 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, 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),
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs
index 967654e97..86dceb2e0 100644
--- a/crates/ra_hir/src/traits.rs
+++ b/crates/ra_hir/src/traits.rs
@@ -22,12 +22,12 @@ impl TraitData {
22 db: &(impl DefDatabase + AstDatabase), 22 db: &(impl DefDatabase + AstDatabase),
23 tr: Trait, 23 tr: Trait,
24 ) -> Arc<TraitData> { 24 ) -> Arc<TraitData> {
25 let (file_id, node) = tr.source(db); 25 let src = tr.source(db);
26 let name = node.name().map(|n| n.as_name()); 26 let name = src.ast.name().map(|n| n.as_name());
27 let module = tr.module(db); 27 let module = tr.module(db);
28 let ctx = LocationCtx::new(db, module, file_id); 28 let ctx = LocationCtx::new(db, module, src.file_id);
29 let auto = node.is_auto(); 29 let auto = src.ast.is_auto();
30 let items = if let Some(item_list) = node.item_list() { 30 let items = if let Some(item_list) = src.ast.item_list() {
31 item_list 31 item_list
32 .impl_items() 32 .impl_items()
33 .map(|item_node| match item_node.kind() { 33 .map(|item_node| match item_node.kind() {
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index 19a64f300..2e3e3863a 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -214,24 +214,8 @@ impl NavigationTarget {
214 hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), 214 hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
215 hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), 215 hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
216 hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), 216 hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
217 hir::ModuleDef::EnumVariant(var) => { 217 hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it),
218 let src = var.source(db); 218 hir::ModuleDef::Trait(it) => NavigationTarget::from_def_source(db, it),
219 NavigationTarget::from_named(
220 src.file_id.original_file(db),
221 &*src.ast,
222 src.ast.doc_comment_text(),
223 src.ast.short_label(),
224 )
225 }
226 hir::ModuleDef::Trait(e) => {
227 let (file_id, node) = e.source(db);
228 NavigationTarget::from_named(
229 file_id.original_file(db),
230 &*node,
231 node.doc_comment_text(),
232 node.short_label(),
233 )
234 }
235 hir::ModuleDef::TypeAlias(it) => NavigationTarget::from_def_source(db, it), 219 hir::ModuleDef::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
236 hir::ModuleDef::BuiltinType(..) => { 220 hir::ModuleDef::BuiltinType(..) => {
237 return None; 221 return None;
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 237e1f4a1..c4004435c 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -124,16 +124,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
124 hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)), 124 hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)),
125 hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), 125 hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)),
126 hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), 126 hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)),
127 hir::ModuleDef::EnumVariant(it) => { 127 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
128 let src = it.source(db);
129 res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
130 }
131 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), 128 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
132 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), 129 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
133 hir::ModuleDef::Trait(it) => { 130 hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
134 let it = it.source(db).1;
135 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
136 }
137 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), 131 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
138 hir::ModuleDef::BuiltinType(_) => { 132 hir::ModuleDef::BuiltinType(_) => {
139 // FIXME: hover for builtin Type ? 133 // FIXME: hover for builtin Type ?