|
6 | 6 |
|
7 | 7 | use std::mem;
|
8 | 8 |
|
9 |
| -use hir::{DefWithBody, HasSource, ModuleSource, Semantics}; |
| 9 | +use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; |
10 | 10 | use once_cell::unsync::Lazy;
|
11 | 11 | use ra_db::{FileId, FileRange, SourceDatabaseExt};
|
12 | 12 | use ra_prof::profile;
|
@@ -123,51 +123,47 @@ impl Definition {
|
123 | 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)" { |
129 |
| - if let Some(parent_module) = module.parent(db) { |
130 |
| - let mut res = FxHashMap::default(); |
131 |
| - let parent_src = parent_module.definition_source(db); |
132 |
| - let file_id = parent_src.file_id.original_file(db); |
| 128 | + // FIXME: |
| 129 | + // The following logic are wrong that it does not search |
| 130 | + // for submodules within other files recursively. |
133 | 131 |
|
134 |
| - match parent_src.value { |
135 |
| - ModuleSource::Module(m) => { |
136 |
| - let range = Some(m.syntax().text_range()); |
137 |
| - res.insert(file_id, range); |
138 |
| - } |
139 |
| - ModuleSource::SourceFile(_) => { |
140 |
| - res.insert(file_id, None); |
141 |
| - res.extend(parent_module.children(db).map(|m| { |
142 |
| - let src = m.definition_source(db); |
143 |
| - (src.file_id.original_file(db), None) |
144 |
| - })); |
145 |
| - } |
| 132 | + if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) { |
| 133 | + let module: Module = module.into(); |
| 134 | + let mut res = FxHashMap::default(); |
| 135 | + let src = module.definition_source(db); |
| 136 | + let file_id = src.file_id.original_file(db); |
| 137 | + |
| 138 | + match src.value { |
| 139 | + ModuleSource::Module(m) => { |
| 140 | + let range = Some(m.syntax().text_range()); |
| 141 | + res.insert(file_id, range); |
| 142 | + } |
| 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 | 155 | let source_root_id = db.file_source_root(file_id);
|
153 | 156 | let source_root = db.source_root(source_root_id);
|
154 | 157 | let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
|
155 | 158 |
|
156 |
| - // FIXME: add "pub(in path)" |
157 |
| - |
158 |
| - if vis.as_str() == "pub(crate)" { |
159 |
| - return SearchScope::new(res); |
160 |
| - } |
161 |
| - if vis.as_str() == "pub" { |
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); |
| 159 | + let krate = module.krate(); |
| 160 | + for rev_dep in krate.reverse_dependencies(db) { |
| 161 | + let root_file = rev_dep.root_file(db); |
| 162 | + let source_root_id = db.file_source_root(root_file); |
| 163 | + let source_root = db.source_root(source_root_id); |
| 164 | + res.extend(source_root.walk().map(|id| (id, None))); |
170 | 165 | }
|
| 166 | + return SearchScope::new(res); |
171 | 167 | }
|
172 | 168 |
|
173 | 169 | let mut res = FxHashMap::default();
|
|
0 commit comments