aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/query_definitions.rs48
1 files changed, 36 insertions, 12 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 3c90e29fe..3b73208e6 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -12,6 +12,7 @@ use ra_db::{SourceRootId, FileId, Cancelable,};
12 12
13use crate::{ 13use crate::{
14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId, 14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, MFileId,
15 macros::MacroCallLoc,
15 db::HirDatabase, 16 db::HirDatabase,
16 function::FnScopes, 17 function::FnScopes,
17 module::{ 18 module::{
@@ -123,25 +124,48 @@ pub(crate) fn modules<'a>(
123 124
124pub(super) fn input_module_items( 125pub(super) fn input_module_items(
125 db: &impl HirDatabase, 126 db: &impl HirDatabase,
126 source_root: SourceRootId, 127 source_root_id: SourceRootId,
127 module_id: ModuleId, 128 module_id: ModuleId,
128) -> Cancelable<Arc<InputModuleItems>> { 129) -> Cancelable<Arc<InputModuleItems>> {
129 let module_tree = db.module_tree(source_root)?; 130 let module_tree = db.module_tree(source_root_id)?;
130 let source = module_id.source(&module_tree); 131 let source = module_id.source(&module_tree);
131 let mfile_id = source.file_id().into(); 132 let mfile_id = source.file_id().into();
132 let file_items = db.file_items(mfile_id); 133 let file_items = db.file_items(mfile_id);
133 let res = match source.resolve(db) { 134 let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| {
134 ModuleSourceNode::SourceFile(it) => { 135 for item in items {
135 let items = it.borrowed().items(); 136 match item {
136 InputModuleItems::new(mfile_id, &file_items, items) 137 ast::ItemOrMacro::Item(it) => {
138 acc.add_item(mfile_id, &file_items, it);
139 }
140 ast::ItemOrMacro::Macro(macro_call) => {
141 let item_id = file_items.id_of_unchecked(macro_call.syntax());
142 let loc = MacroCallLoc {
143 source_root_id,
144 module_id,
145 source_item_id: SourceItemId {
146 mfile_id,
147 item_id: Some(item_id),
148 },
149 };
150 let id = loc.id(db);
151 let mfile_id = MFileId::Macro(id);
152 let file_items = db.file_items(mfile_id);
153 //FIXME: expand recursively
154 for item in db.m_source_file(mfile_id).borrowed().items() {
155 acc.add_item(mfile_id, &file_items, item);
156 }
157 }
158 }
137 } 159 }
160 };
161
162 let mut res = InputModuleItems::default();
163 match source.resolve(db) {
164 ModuleSourceNode::SourceFile(it) => fill(&mut res, &mut it.borrowed().items_with_macros()),
138 ModuleSourceNode::Module(it) => { 165 ModuleSourceNode::Module(it) => {
139 let items = it 166 if let Some(item_list) = it.borrowed().item_list() {
140 .borrowed() 167 fill(&mut res, &mut item_list.items_with_macros())
141 .item_list() 168 }
142 .into_iter()
143 .flat_map(|it| it.items());
144 InputModuleItems::new(mfile_id, &file_items, items)
145 } 169 }
146 }; 170 };
147 Ok(Arc::new(res)) 171 Ok(Arc::new(res))