aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs7
-rw-r--r--crates/ra_hir/src/docs.rs2
-rw-r--r--crates/ra_hir/src/generics.rs4
-rw-r--r--crates/ra_hir/src/impl_block.rs18
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs6
5 files changed, 20 insertions, 17 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 0a750b590..5b56f890e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -442,11 +442,8 @@ impl HasSource for Union {
442} 442}
443 443
444impl Union { 444impl Union {
445 pub fn source( 445 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
446 self, 446 self.id.source(db).into()
447 db: &(impl DefDatabase + AstDatabase),
448 ) -> (HirFileId, TreeArc<ast::StructDef>) {
449 self.id.source(db)
450 } 447 }
451 448
452 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 449 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs
index 0cb0c0db8..f736f3875 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -82,7 +82,7 @@ pub(crate) fn documentation_query(
82 DocDef::Static(it) => docs_from_ast(&*it.source(db).ast), 82 DocDef::Static(it) => docs_from_ast(&*it.source(db).ast),
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).ast),
86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast), 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),
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 08d711754..0b8bd5700 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -70,7 +70,7 @@ impl GenericParams {
70 match def { 70 match def {
71 GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start), 71 GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start),
72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start), 72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), 73 GenericDef::Union(it) => generics.fill(&*it.source(db).ast, start),
74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), 74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
75 GenericDef::Trait(it) => { 75 GenericDef::Trait(it) => {
76 // traits get the Self type as an implicit first type parameter 76 // traits get the Self type as an implicit first type parameter
@@ -82,7 +82,7 @@ impl GenericParams {
82 generics.fill(&*it.source(db).ast, 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).ast, start),
86 } 86 }
87 87
88 Arc::new(generics) 88 Arc::new(generics)
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index a0d3b33fe..8194f38d4 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -8,7 +8,7 @@ use ra_syntax::{
8}; 8};
9 9
10use crate::{ 10use crate::{
11 Const, TypeAlias, Function, HirFileId, AstDatabase, 11 Const, TypeAlias, Function, HirFileId, AstDatabase, HasSource, Source,
12 HirDatabase, DefDatabase, TraitRef, 12 HirDatabase, DefDatabase, TraitRef,
13 type_ref::TypeRef, 13 type_ref::TypeRef,
14 ids::LocationCtx, 14 ids::LocationCtx,
@@ -44,6 +44,15 @@ pub struct ImplBlock {
44 impl_id: ImplId, 44 impl_id: ImplId,
45} 45}
46 46
47impl HasSource for ImplBlock {
48 type Ast = TreeArc<ast::ImplBlock>;
49 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
50 let source_map = db.impls_in_module_with_source_map(self.module).1;
51 let (file_id, source) = self.module.definition_source(db);
52 (file_id, source_map.get(&source, self.impl_id)).into()
53 }
54}
55
47impl ImplBlock { 56impl ImplBlock {
48 pub(crate) fn containing( 57 pub(crate) fn containing(
49 module_impl_blocks: Arc<ModuleImplBlocks>, 58 module_impl_blocks: Arc<ModuleImplBlocks>,
@@ -58,13 +67,10 @@ impl ImplBlock {
58 } 67 }
59 68
60 /// Returns the syntax of the impl block 69 /// Returns the syntax of the impl block
61 pub fn source( 70 pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
62 &self,
63 db: &(impl DefDatabase + AstDatabase),
64 ) -> (HirFileId, TreeArc<ast::ImplBlock>) {
65 let source_map = db.impls_in_module_with_source_map(self.module).1; 71 let source_map = db.impls_in_module_with_source_map(self.module).1;
66 let (file_id, source) = self.module.definition_source(db); 72 let (file_id, source) = self.module.definition_source(db);
67 (file_id, source_map.get(&source, self.impl_id)) 73 (file_id, source_map.get(&source, self.impl_id)).into()
68 } 74 }
69 75
70 pub fn id(&self) -> ImplId { 76 pub fn id(&self) -> ImplId {
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index 2e3e3863a..640d68544 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -228,12 +228,12 @@ impl NavigationTarget {
228 db: &RootDatabase, 228 db: &RootDatabase,
229 impl_block: hir::ImplBlock, 229 impl_block: hir::ImplBlock,
230 ) -> NavigationTarget { 230 ) -> NavigationTarget {
231 let (file_id, node) = impl_block.source(db); 231 let src = impl_block.source(db);
232 NavigationTarget::from_syntax( 232 NavigationTarget::from_syntax(
233 file_id.as_original_file(), 233 src.file_id.as_original_file(),
234 "impl".into(), 234 "impl".into(),
235 None, 235 None,
236 node.syntax(), 236 src.ast.syntax(),
237 None, 237 None,
238 None, 238 None,
239 ) 239 )