aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/query_definitions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r--crates/ra_hir/src/query_definitions.rs58
1 files changed, 3 insertions, 55 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 24cb5c752..985a02410 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -6,16 +6,14 @@ use std::{
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use ra_syntax::{ 7use ra_syntax::{
8 AstNode, SyntaxNode, TreeArc, 8 AstNode, SyntaxNode, TreeArc,
9 ast::{self, ModuleItemOwner}
10}; 9};
11use ra_db::SourceRootId; 10use ra_db::SourceRootId;
12 11
13use crate::{ 12use crate::{
14 SourceFileItems, SourceItemId, DefId, HirFileId, ModuleSource, 13 SourceFileItems, SourceItemId, DefId, HirFileId,
15 MacroCallLoc, FnScopes, 14 FnScopes,
16 db::HirDatabase, 15 db::HirDatabase,
17 module_tree::ModuleId, 16 nameres::{ItemMap, Resolver},
18 nameres::{InputModuleItems, ItemMap, Resolver},
19}; 17};
20 18
21pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> { 19pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
@@ -43,56 +41,6 @@ pub(super) fn file_item(
43 } 41 }
44} 42}
45 43
46pub(super) fn input_module_items(
47 db: &impl HirDatabase,
48 source_root_id: SourceRootId,
49 module_id: ModuleId,
50) -> Arc<InputModuleItems> {
51 let module_tree = db.module_tree(source_root_id);
52 let source = module_id.source(&module_tree);
53 let file_id = source.file_id;
54 let source = ModuleSource::from_source_item_id(db, source);
55 let file_items = db.file_items(file_id);
56 let fill = |acc: &mut InputModuleItems, items: &mut Iterator<Item = ast::ItemOrMacro>| {
57 for item in items {
58 match item {
59 ast::ItemOrMacro::Item(it) => {
60 acc.add_item(file_id, &file_items, it);
61 }
62 ast::ItemOrMacro::Macro(macro_call) => {
63 let item_id = file_items.id_of_unchecked(macro_call.syntax());
64 let loc = MacroCallLoc {
65 source_root_id,
66 module_id,
67 source_item_id: SourceItemId {
68 file_id,
69 item_id: Some(item_id),
70 },
71 };
72 let id = loc.id(db);
73 let file_id = HirFileId::from(id);
74 let file_items = db.file_items(file_id);
75 //FIXME: expand recursively
76 for item in db.hir_source_file(file_id).items() {
77 acc.add_item(file_id, &file_items, item);
78 }
79 }
80 }
81 }
82 };
83
84 let mut res = InputModuleItems::default();
85 match source {
86 ModuleSource::SourceFile(it) => fill(&mut res, &mut it.items_with_macros()),
87 ModuleSource::Module(it) => {
88 if let Some(item_list) = it.item_list() {
89 fill(&mut res, &mut item_list.items_with_macros())
90 }
91 }
92 };
93 Arc::new(res)
94}
95
96pub(super) fn item_map(db: &impl HirDatabase, source_root: SourceRootId) -> Arc<ItemMap> { 44pub(super) fn item_map(db: &impl HirDatabase, source_root: SourceRootId) -> Arc<ItemMap> {
97 let start = Instant::now(); 45 let start = Instant::now();
98 let module_tree = db.module_tree(source_root); 46 let module_tree = db.module_tree(source_root);