diff options
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 01afa84c4..7ce8d17e6 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -7,12 +7,14 @@ use ra_db::{LocationIntener, Cancelable, SourceRootId}; | |||
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, | 9 | DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, |
10 | Module, Function, | 10 | Function, |
11 | db::HirDatabase, | 11 | db::HirDatabase, |
12 | type_ref::TypeRef, | 12 | type_ref::TypeRef, |
13 | module::{ModuleSourceNode, ModuleId}, | 13 | module_tree::ModuleId, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | use crate::code_model_api::{Module, ModuleSource}; | ||
17 | |||
16 | #[derive(Debug, Clone, PartialEq, Eq)] | 18 | #[derive(Debug, Clone, PartialEq, Eq)] |
17 | pub struct ImplBlock { | 19 | pub struct ImplBlock { |
18 | module_impl_blocks: Arc<ModuleImplBlocks>, | 20 | module_impl_blocks: Arc<ModuleImplBlocks>, |
@@ -64,7 +66,7 @@ impl ImplData { | |||
64 | ) -> Self { | 66 | ) -> Self { |
65 | let target_trait = node.target_type().map(TypeRef::from_ast); | 67 | let target_trait = node.target_type().map(TypeRef::from_ast); |
66 | let target_type = TypeRef::from_ast_opt(node.target_type()); | 68 | let target_type = TypeRef::from_ast_opt(node.target_type()); |
67 | let file_id = module.source().file_id(); | 69 | let module_loc = module.def_id.loc(db); |
68 | let items = if let Some(item_list) = node.item_list() { | 70 | let items = if let Some(item_list) = node.item_list() { |
69 | item_list | 71 | item_list |
70 | .impl_items() | 72 | .impl_items() |
@@ -75,14 +77,14 @@ impl ImplData { | |||
75 | ast::ImplItem::TypeDef(..) => DefKind::Item, | 77 | ast::ImplItem::TypeDef(..) => DefKind::Item, |
76 | }; | 78 | }; |
77 | let item_id = file_items.id_of_unchecked(item_node.syntax()); | 79 | let item_id = file_items.id_of_unchecked(item_node.syntax()); |
80 | let source_item_id = SourceItemId { | ||
81 | file_id: module_loc.source_item_id.file_id, | ||
82 | item_id: Some(item_id), | ||
83 | }; | ||
78 | let def_loc = DefLoc { | 84 | let def_loc = DefLoc { |
79 | kind, | 85 | kind, |
80 | source_root_id: module.source_root_id, | 86 | source_item_id, |
81 | module_id: module.module_id, | 87 | ..module_loc |
82 | source_item_id: SourceItemId { | ||
83 | file_id, | ||
84 | item_id: Some(item_id), | ||
85 | }, | ||
86 | }; | 88 | }; |
87 | let def_id = def_loc.id(db); | 89 | let def_id = def_loc.id(db); |
88 | match item_node { | 90 | match item_node { |
@@ -148,13 +150,13 @@ impl ModuleImplBlocks { | |||
148 | } | 150 | } |
149 | 151 | ||
150 | fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { | 152 | fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { |
151 | let module_source_node = module.source().resolve(db); | 153 | let (file_id, module_source) = module.defenition_source(db)?; |
152 | let node = match &module_source_node { | 154 | let node = match &module_source { |
153 | ModuleSourceNode::SourceFile(node) => node.borrowed().syntax(), | 155 | ModuleSource::SourceFile(node) => node.borrowed().syntax(), |
154 | ModuleSourceNode::Module(node) => node.borrowed().syntax(), | 156 | ModuleSource::Module(node) => node.borrowed().syntax(), |
155 | }; | 157 | }; |
156 | 158 | ||
157 | let source_file_items = db.file_items(module.source().file_id()); | 159 | let source_file_items = db.file_items(file_id.into()); |
158 | 160 | ||
159 | for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { | 161 | for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) { |
160 | let impl_block = ImplData::from_ast(db, &source_file_items, &module, impl_block_ast); | 162 | let impl_block = ImplData::from_ast(db, &source_file_items, &module, impl_block_ast); |
@@ -174,7 +176,7 @@ pub(crate) fn impls_in_module( | |||
174 | module_id: ModuleId, | 176 | module_id: ModuleId, |
175 | ) -> Cancelable<Arc<ModuleImplBlocks>> { | 177 | ) -> Cancelable<Arc<ModuleImplBlocks>> { |
176 | let mut result = ModuleImplBlocks::new(); | 178 | let mut result = ModuleImplBlocks::new(); |
177 | let module = Module::new(db, source_root_id, module_id)?; | 179 | let module = Module::from_module_id(db, source_root_id, module_id)?; |
178 | result.collect(db, module)?; | 180 | result.collect(db, module)?; |
179 | Ok(Arc::new(result)) | 181 | Ok(Arc::new(result)) |
180 | } | 182 | } |