aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index bde0be37b..c3bd31d6b 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -13,7 +13,7 @@ use ra_syntax::{
13}; 13};
14 14
15use crate::{ 15use crate::{
16 HirDatabase, Function, SourceItemId, 16 HirDatabase, Function, SourceItemId, ModuleDef,
17 DefKind, DefLoc, AsName, Module, 17 DefKind, DefLoc, AsName, Module,
18}; 18};
19 19
@@ -84,9 +84,13 @@ pub fn module_from_child_node(
84 84
85fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> { 85fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option<Module> {
86 let source_root_id = db.file_source_root(source.file_id.as_original_file()); 86 let source_root_id = db.file_source_root(source.file_id.as_original_file());
87 let module_tree = db.module_tree(source_root_id); 87 db.source_root_crates(source_root_id)
88 let module_id = module_tree.find_module_by_source(source)?; 88 .iter()
89 Some(Module::from_module_id(db, source_root_id, module_id)) 89 .find_map(|&krate| {
90 let module_tree = db.module_tree(krate);
91 let module_id = module_tree.find_module_by_source(source)?;
92 Some(Module { krate, module_id })
93 })
90} 94}
91 95
92pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> { 96pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> {
@@ -110,8 +114,8 @@ pub fn function_from_module(
110 module: &Module, 114 module: &Module,
111 fn_def: &ast::FnDef, 115 fn_def: &ast::FnDef,
112) -> Function { 116) -> Function {
113 let loc = module.def_id.loc(db); 117 let (file_id, _) = module.definition_source(db);
114 let file_id = loc.source_item_id.file_id; 118 let file_id = file_id.into();
115 let file_items = db.file_items(file_id); 119 let file_items = db.file_items(file_id);
116 let item_id = file_items.id_of(file_id, fn_def.syntax()); 120 let item_id = file_items.id_of(file_id, fn_def.syntax());
117 let source_item_id = SourceItemId { 121 let source_item_id = SourceItemId {
@@ -119,9 +123,8 @@ pub fn function_from_module(
119 item_id: Some(item_id), 123 item_id: Some(item_id),
120 }; 124 };
121 let def_loc = DefLoc { 125 let def_loc = DefLoc {
126 module: module.clone(),
122 kind: DefKind::Function, 127 kind: DefKind::Function,
123 source_root_id: loc.source_root_id,
124 module_id: loc.module_id,
125 source_item_id, 128 source_item_id,
126 }; 129 };
127 Function::new(def_loc.id(db)) 130 Function::new(def_loc.id(db))
@@ -141,14 +144,17 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te
141 Some(it) => it, 144 Some(it) => it,
142 None => return Vec::new(), 145 None => return Vec::new(),
143 }; 146 };
144 let loc = module.def_id.loc(db); 147 let items = db.lower_module_module(module);
145 let items = db.lower_module_module(loc.source_root_id, loc.module_id);
146 let mut res = Vec::new(); 148 let mut res = Vec::new();
147 149
148 for macro_call_id in items 150 for macro_call_id in items
149 .declarations 151 .declarations
150 .iter() 152 .iter()
151 .filter_map(|(_, it)| it.take_types()) 153 .filter_map(|(_, it)| it.clone().take_types())
154 .filter_map(|it| match it {
155 ModuleDef::Def(it) => Some(it),
156 _ => None,
157 })
152 .filter_map(|it| it.loc(db).source_item_id.file_id.as_macro_call_id()) 158 .filter_map(|it| it.loc(db).source_item_id.file_id.as_macro_call_id())
153 { 159 {
154 if let Some(exp) = db.expand_macro_invocation(macro_call_id) { 160 if let Some(exp) = db.expand_macro_invocation(macro_call_id) {