aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/impl_block.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r--crates/ra_hir/src/impl_block.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index a0d3b33fe..fb9daf1bf 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 src = self.module.definition_source(db);
52 Source { file_id: src.file_id, ast: source_map.get(&src.ast, self.impl_id) }
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>,
@@ -57,16 +66,6 @@ impl ImplBlock {
57 ImplBlock { module, impl_id } 66 ImplBlock { module, impl_id }
58 } 67 }
59 68
60 /// Returns the syntax of the impl block
61 pub fn source(
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;
66 let (file_id, source) = self.module.definition_source(db);
67 (file_id, source_map.get(&source, self.impl_id))
68 }
69
70 pub fn id(&self) -> ImplId { 69 pub fn id(&self) -> ImplId {
71 self.impl_id 70 self.impl_id
72 } 71 }
@@ -201,8 +200,8 @@ impl ModuleImplBlocks {
201 impls_by_def: FxHashMap::default(), 200 impls_by_def: FxHashMap::default(),
202 }; 201 };
203 202
204 let (file_id, module_source) = m.module.definition_source(db); 203 let src = m.module.definition_source(db);
205 let node = match &module_source { 204 let node = match &src.ast {
206 ModuleSource::SourceFile(node) => node.syntax(), 205 ModuleSource::SourceFile(node) => node.syntax(),
207 ModuleSource::Module(node) => { 206 ModuleSource::Module(node) => {
208 node.item_list().expect("inline module should have item list").syntax() 207 node.item_list().expect("inline module should have item list").syntax()
@@ -210,7 +209,7 @@ impl ModuleImplBlocks {
210 }; 209 };
211 210
212 for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { 211 for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
213 let impl_block = ImplData::from_ast(db, file_id, m.module, impl_block_ast); 212 let impl_block = ImplData::from_ast(db, src.file_id, m.module, impl_block_ast);
214 let id = m.impls.alloc(impl_block); 213 let id = m.impls.alloc(impl_block);
215 for &impl_item in &m.impls[id].items { 214 for &impl_item in &m.impls[id].items {
216 m.impls_by_def.insert(impl_item, id); 215 m.impls_by_def.insert(impl_item, id);