aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-24 20:45:55 +0000
committerEdwin Cheng <[email protected]>2020-03-24 20:45:55 +0000
commitd606521723d2635a21e6dd821b314f8e3127cbf9 (patch)
tree268ca130f293fd9a4345620e2546554613829610 /crates
parentbcfb3700ce5249d79368eda974b738617a83f894 (diff)
Use visibility_of in search
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_db/src/search.rs66
1 files changed, 31 insertions, 35 deletions
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs
index 117454695..05a0eed30 100644
--- a/crates/ra_ide_db/src/search.rs
+++ b/crates/ra_ide_db/src/search.rs
@@ -6,7 +6,7 @@
6 6
7use std::mem; 7use std::mem;
8 8
9use hir::{DefWithBody, HasSource, ModuleSource, Semantics}; 9use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility};
10use once_cell::unsync::Lazy; 10use once_cell::unsync::Lazy;
11use ra_db::{FileId, FileRange, SourceDatabaseExt}; 11use ra_db::{FileId, FileRange, SourceDatabaseExt};
12use ra_prof::profile; 12use ra_prof::profile;
@@ -123,51 +123,47 @@ impl Definition {
123 return SearchScope::new(res); 123 return SearchScope::new(res);
124 } 124 }
125 125
126 let vis = self.visibility(db).as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); 126 let vis = self.visibility(db);
127 127
128 if vis.as_str() == "pub(super)" { 128 // FIXME:
129 if let Some(parent_module) = module.parent(db) { 129 // The following logic are wrong that it does not search
130 let mut res = FxHashMap::default(); 130 // for submodules within other files recursively.
131 let parent_src = parent_module.definition_source(db);
132 let file_id = parent_src.file_id.original_file(db);
133 131
134 match parent_src.value { 132 if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) {
135 ModuleSource::Module(m) => { 133 let module: Module = module.into();
136 let range = Some(m.syntax().text_range()); 134 let mut res = FxHashMap::default();
137 res.insert(file_id, range); 135 let src = module.definition_source(db);
138 } 136 let file_id = src.file_id.original_file(db);
139 ModuleSource::SourceFile(_) => { 137
140 res.insert(file_id, None); 138 match src.value {
141 res.extend(parent_module.children(db).map(|m| { 139 ModuleSource::Module(m) => {
142 let src = m.definition_source(db); 140 let range = Some(m.syntax().text_range());
143 (src.file_id.original_file(db), None) 141 res.insert(file_id, range);
144 })); 142 }
145 } 143 ModuleSource::SourceFile(_) => {
144 res.insert(file_id, None);
145 res.extend(module.children(db).map(|m| {
146 let src = m.definition_source(db);
147 (src.file_id.original_file(db), None)
148 }));
146 } 149 }
147 return SearchScope::new(res);
148 } 150 }
151 return SearchScope::new(res);
149 } 152 }
150 153
151 if vis.as_str() != "" { 154 if let Some(Visibility::Public) = vis {
152 let source_root_id = db.file_source_root(file_id); 155 let source_root_id = db.file_source_root(file_id);
153 let source_root = db.source_root(source_root_id); 156 let source_root = db.source_root(source_root_id);
154 let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>(); 157 let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
155 158
156 // FIXME: add "pub(in path)" 159 let krate = module.krate();
157 160 for rev_dep in krate.reverse_dependencies(db) {
158 if vis.as_str() == "pub(crate)" { 161 let root_file = rev_dep.root_file(db);
159 return SearchScope::new(res); 162 let source_root_id = db.file_source_root(root_file);
160 } 163 let source_root = db.source_root(source_root_id);
161 if vis.as_str() == "pub" { 164 res.extend(source_root.walk().map(|id| (id, None)));
162 let krate = module.krate();
163 for rev_dep in krate.reverse_dependencies(db) {
164 let root_file = rev_dep.root_file(db);
165 let source_root_id = db.file_source_root(root_file);
166 let source_root = db.source_root(source_root_id);
167 res.extend(source_root.walk().map(|id| (id, None)));
168 }
169 return SearchScope::new(res);
170 } 165 }
166 return SearchScope::new(res);
171 } 167 }
172 168
173 let mut res = FxHashMap::default(); 169 let mut res = FxHashMap::default();