aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-21 19:08:08 +0000
committerLukas Wirth <[email protected]>2021-03-23 10:32:10 +0000
commitbad4e48672f928644457cece3b7e21dd78ea1e9b (patch)
treeae9a17f4f08b05204b78a5d015ff7ece1305e88d /crates/ide_db/src
parent1efd220f2f844596dd22bfd73a8a0c596354be38 (diff)
Set up a search scope when searching for mbe macro references
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/search.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 8e93de277..5fdcb13cf 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -7,7 +7,7 @@
7use std::{convert::TryInto, mem}; 7use std::{convert::TryInto, mem};
8 8
9use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt}; 9use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
10use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; 10use hir::{DefWithBody, HasAttrs, HasSource, Module, ModuleSource, Semantics, Visibility};
11use once_cell::unsync::Lazy; 11use once_cell::unsync::Lazy;
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
13use syntax::{ast, match_ast, AstNode, TextRange, TextSize}; 13use syntax::{ast, match_ast, AstNode, TextRange, TextSize};
@@ -244,9 +244,8 @@ impl Definition {
244 return SearchScope::new(res); 244 return SearchScope::new(res);
245 } 245 }
246 246
247 if let Some(Visibility::Public) = vis { 247 let rev_dep_scope = || {
248 let mut res = FxHashMap::default(); 248 let mut res = FxHashMap::default();
249
250 let krate = module.krate(); 249 let krate = module.krate();
251 for rev_dep in krate.transitive_reverse_dependencies(db) { 250 for rev_dep in krate.transitive_reverse_dependencies(db) {
252 let root_file = rev_dep.root_file(db); 251 let root_file = rev_dep.root_file(db);
@@ -254,7 +253,25 @@ impl Definition {
254 let source_root = db.source_root(source_root_id); 253 let source_root = db.source_root(source_root_id);
255 res.extend(source_root.iter().map(|id| (id, None))); 254 res.extend(source_root.iter().map(|id| (id, None)));
256 } 255 }
257 return SearchScope::new(res); 256 SearchScope::new(res)
257 };
258
259 if let Definition::Macro(macro_def) = self {
260 if macro_def.is_declarative() {
261 return if macro_def.attrs(db).by_key("macro_export").exists() {
262 rev_dep_scope()
263 } else {
264 let source_root_id = db.file_source_root(file_id);
265 let source_root = db.source_root(source_root_id);
266 SearchScope::new(
267 source_root.iter().map(|id| (id, None)).collect::<FxHashMap<_, _>>(),
268 )
269 };
270 }
271 }
272
273 if let Some(Visibility::Public) = vis {
274 return rev_dep_scope();
258 } 275 }
259 276
260 let mut res = FxHashMap::default(); 277 let mut res = FxHashMap::default();