Skip to content

Commit d606521

Browse files
committed
Use visibility_of in search
1 parent bcfb370 commit d606521

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

crates/ra_ide_db/src/search.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::mem;
88

9-
use hir::{DefWithBody, HasSource, ModuleSource, Semantics};
9+
use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility};
1010
use once_cell::unsync::Lazy;
1111
use ra_db::{FileId, FileRange, SourceDatabaseExt};
1212
use ra_prof::profile;
@@ -123,51 +123,47 @@ impl Definition {
123123
return SearchScope::new(res);
124124
}
125125

126-
let vis = self.visibility(db).as_ref().map(|v| v.syntax().to_string()).unwrap_or_default();
126+
let vis = self.visibility(db);
127127

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.
133131

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+
}));
146149
}
147-
return SearchScope::new(res);
148150
}
151+
return SearchScope::new(res);
149152
}
150153

151-
if vis.as_str() != "" {
154+
if let Some(Visibility::Public) = vis {
152155
let source_root_id = db.file_source_root(file_id);
153156
let source_root = db.source_root(source_root_id);
154157
let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
155158

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)));
170165
}
166+
return SearchScope::new(res);
171167
}
172168

173169
let mut res = FxHashMap::default();

0 commit comments

Comments
 (0)