diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/nameres/lower.rs | 84 |
1 files changed, 52 insertions, 32 deletions
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index dd3bf245f..35bdbafbf 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs | |||
@@ -33,48 +33,68 @@ impl InputModuleItems { | |||
33 | let source = module_id.source(&module_tree); | 33 | let source = module_id.source(&module_tree); |
34 | let file_id = source.file_id; | 34 | let file_id = source.file_id; |
35 | let source = ModuleSource::from_source_item_id(db, source); | 35 | let source = ModuleSource::from_source_item_id(db, source); |
36 | let file_items = db.file_items(file_id); | ||
37 | let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| { | ||
38 | for item in items { | ||
39 | match item { | ||
40 | ast::ItemOrMacro::Item(it) => { | ||
41 | acc.add_item(file_id, &file_items, it); | ||
42 | } | ||
43 | ast::ItemOrMacro::Macro(macro_call) => { | ||
44 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); | ||
45 | let loc = MacroCallLoc { | ||
46 | source_root_id, | ||
47 | module_id, | ||
48 | source_item_id: SourceItemId { | ||
49 | file_id, | ||
50 | item_id: Some(item_id), | ||
51 | }, | ||
52 | }; | ||
53 | let id = loc.id(db); | ||
54 | let file_id = HirFileId::from(id); | ||
55 | let file_items = db.file_items(file_id); | ||
56 | //FIXME: expand recursively | ||
57 | for item in db.hir_source_file(file_id).items() { | ||
58 | acc.add_item(file_id, &file_items, item); | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | }; | ||
64 | |||
65 | let mut res = InputModuleItems::default(); | 36 | let mut res = InputModuleItems::default(); |
66 | match source { | 37 | match source { |
67 | ModuleSource::SourceFile(it) => fill(&mut res, &mut it.items_with_macros()), | 38 | ModuleSource::SourceFile(it) => res.fill( |
39 | db, | ||
40 | source_root_id, | ||
41 | module_id, | ||
42 | file_id, | ||
43 | &mut it.items_with_macros(), | ||
44 | ), | ||
68 | ModuleSource::Module(it) => { | 45 | ModuleSource::Module(it) => { |
69 | if let Some(item_list) = it.item_list() { | 46 | if let Some(item_list) = it.item_list() { |
70 | fill(&mut res, &mut item_list.items_with_macros()) | 47 | res.fill( |
48 | db, | ||
49 | source_root_id, | ||
50 | module_id, | ||
51 | file_id, | ||
52 | &mut item_list.items_with_macros(), | ||
53 | ) | ||
71 | } | 54 | } |
72 | } | 55 | } |
73 | }; | 56 | }; |
74 | Arc::new(res) | 57 | Arc::new(res) |
75 | } | 58 | } |
76 | 59 | ||
77 | pub(crate) fn add_item( | 60 | fn fill( |
61 | &mut self, | ||
62 | db: &impl HirDatabase, | ||
63 | source_root_id: SourceRootId, | ||
64 | module_id: ModuleId, | ||
65 | file_id: HirFileId, | ||
66 | items: &mut Iterator<Item = ast::ItemOrMacro>, | ||
67 | ) { | ||
68 | let file_items = db.file_items(file_id); | ||
69 | |||
70 | for item in items { | ||
71 | match item { | ||
72 | ast::ItemOrMacro::Item(it) => { | ||
73 | self.add_item(file_id, &file_items, it); | ||
74 | } | ||
75 | ast::ItemOrMacro::Macro(macro_call) => { | ||
76 | let item_id = file_items.id_of_unchecked(macro_call.syntax()); | ||
77 | let loc = MacroCallLoc { | ||
78 | source_root_id, | ||
79 | module_id, | ||
80 | source_item_id: SourceItemId { | ||
81 | file_id, | ||
82 | item_id: Some(item_id), | ||
83 | }, | ||
84 | }; | ||
85 | let id = loc.id(db); | ||
86 | let file_id = HirFileId::from(id); | ||
87 | let file_items = db.file_items(file_id); | ||
88 | //FIXME: expand recursively | ||
89 | for item in db.hir_source_file(file_id).items() { | ||
90 | self.add_item(file_id, &file_items, item); | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | fn add_item( | ||
78 | &mut self, | 98 | &mut self, |
79 | file_id: HirFileId, | 99 | file_id: HirFileId, |
80 | file_items: &SourceFileItems, | 100 | file_items: &SourceFileItems, |