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.rs46
1 files changed, 4 insertions, 42 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 4a9921a85..902110913 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -7,13 +7,13 @@
7/// purely for "IDE needs". 7/// purely for "IDE needs".
8use ra_db::{FileId, FilePosition}; 8use ra_db::{FileId, FilePosition};
9use ra_syntax::{ 9use ra_syntax::{
10 SmolStr, TextRange, SyntaxNode, 10 SyntaxNode,
11 ast::{self, AstNode, NameOwner}, 11 ast::{self, AstNode, NameOwner},
12 algo::{find_node_at_offset, find_leaf_at_offset}, 12 algo::{find_node_at_offset, find_leaf_at_offset},
13}; 13};
14 14
15use crate::{ 15use crate::{
16 HirDatabase, Function, ModuleDef, Struct, Enum, 16 HirDatabase, Function, Struct, Enum,
17 AsName, Module, HirFileId, Crate, Trait, Resolver, 17 AsName, Module, HirFileId, Crate, Trait, Resolver,
18 ids::{LocationCtx, SourceFileItemId}, 18 ids::{LocationCtx, SourceFileItemId},
19 expr 19 expr
@@ -80,8 +80,8 @@ fn module_from_source(
80 let source_root_id = db.file_source_root(file_id.as_original_file()); 80 let source_root_id = db.file_source_root(file_id.as_original_file());
81 db.source_root_crates(source_root_id).iter().map(|&crate_id| Crate { crate_id }).find_map( 81 db.source_root_crates(source_root_id).iter().map(|&crate_id| Crate { crate_id }).find_map(
82 |krate| { 82 |krate| {
83 let module_tree = db.module_tree(krate); 83 let def_map = db.crate_def_map(krate);
84 let module_id = module_tree.find_module_by_source(file_id, decl_id)?; 84 let module_id = def_map.find_module_by_source(file_id, decl_id)?;
85 Some(Module { krate, module_id }) 85 Some(Module { krate, module_id })
86 }, 86 },
87 ) 87 )
@@ -152,44 +152,6 @@ pub fn trait_from_module(
152 Trait { id: ctx.to_def(trait_def) } 152 Trait { id: ctx.to_def(trait_def) }
153} 153}
154 154
155pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> {
156 let module = match module_from_file_id(db, file_id) {
157 Some(it) => it,
158 None => return Vec::new(),
159 };
160 let items = db.lower_module(module);
161 let mut res = Vec::new();
162
163 for macro_call_id in items
164 .declarations
165 .iter()
166 .filter_map(|(_, it)| it.clone().take_types())
167 .filter_map(|it| match it {
168 ModuleDef::Trait(it) => Some(it),
169 _ => None,
170 })
171 .filter_map(|it| it.source(db).0.as_macro_call_id())
172 {
173 if let Some(exp) = db.expand_macro_invocation(macro_call_id) {
174 let loc = macro_call_id.loc(db);
175 let syntax = db.file_item(loc.source_item_id);
176 let macro_call = ast::MacroCall::cast(&syntax).unwrap();
177 let off = macro_call.token_tree().unwrap().syntax().range().start();
178 let file = exp.file();
179 for trait_def in file.syntax().descendants().filter_map(ast::TraitDef::cast) {
180 if let Some(name) = trait_def.name() {
181 let dst_range = name.syntax().range();
182 if let Some(src_range) = exp.map_range_back(dst_range) {
183 res.push((name.text().clone(), src_range + off))
184 }
185 }
186 }
187 }
188 }
189
190 res
191}
192
193pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { 155pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver {
194 let file_id = position.file_id; 156 let file_id = position.file_id;
195 let file = db.parse(file_id); 157 let file = db.parse(file_id);