diff options
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index c0b3f1cd4..f523f0647 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -13,18 +13,14 @@ use ra_syntax::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | HirDatabase, Function, SourceItemId, ModuleDef, | 16 | HirDatabase, Function, ModuleDef, |
17 | AsName, Module, | 17 | AsName, Module, HirFileId, |
18 | ids::LocationCtx, | 18 | ids::{LocationCtx, SourceFileItemId}, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | /// Locates the module by `FileId`. Picks topmost module in the file. | 21 | /// Locates the module by `FileId`. Picks topmost module in the file. |
22 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Option<Module> { | 22 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Option<Module> { |
23 | let module_source = SourceItemId { | 23 | module_from_source(db, file_id.into(), None) |
24 | file_id: file_id.into(), | ||
25 | item_id: None, | ||
26 | }; | ||
27 | module_from_source(db, module_source) | ||
28 | } | 24 | } |
29 | 25 | ||
30 | /// Locates the child module by `mod child;` declaration. | 26 | /// Locates the child module by `mod child;` declaration. |
@@ -59,11 +55,7 @@ fn module_from_inline( | |||
59 | let file_id = file_id.into(); | 55 | let file_id = file_id.into(); |
60 | let file_items = db.file_items(file_id); | 56 | let file_items = db.file_items(file_id); |
61 | let item_id = file_items.id_of(file_id, module.syntax()); | 57 | let item_id = file_items.id_of(file_id, module.syntax()); |
62 | let source = SourceItemId { | 58 | module_from_source(db, file_id, Some(item_id)) |
63 | file_id, | ||
64 | item_id: Some(item_id), | ||
65 | }; | ||
66 | module_from_source(db, source) | ||
67 | } | 59 | } |
68 | 60 | ||
69 | /// Locates the module by child syntax element within the module | 61 | /// Locates the module by child syntax element within the module |
@@ -83,13 +75,17 @@ pub fn module_from_child_node( | |||
83 | } | 75 | } |
84 | } | 76 | } |
85 | 77 | ||
86 | fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> { | 78 | fn module_from_source( |
87 | let source_root_id = db.file_source_root(source.file_id.as_original_file()); | 79 | db: &impl HirDatabase, |
80 | file_id: HirFileId, | ||
81 | decl_id: Option<SourceFileItemId>, | ||
82 | ) -> Option<Module> { | ||
83 | let source_root_id = db.file_source_root(file_id.as_original_file()); | ||
88 | db.source_root_crates(source_root_id) | 84 | db.source_root_crates(source_root_id) |
89 | .iter() | 85 | .iter() |
90 | .find_map(|&krate| { | 86 | .find_map(|&krate| { |
91 | let module_tree = db.module_tree(krate); | 87 | let module_tree = db.module_tree(krate); |
92 | let module_id = module_tree.find_module_by_source(source)?; | 88 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; |
93 | Some(Module { krate, module_id }) | 89 | Some(Module { krate, module_id }) |
94 | }) | 90 | }) |
95 | } | 91 | } |