mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Use visibility_of in search
This commit is contained in:
parent
bcfb3700ce
commit
d606521723
1 changed files with 31 additions and 35 deletions
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use hir::{DefWithBody, HasSource, ModuleSource, Semantics};
|
use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility};
|
||||||
use once_cell::unsync::Lazy;
|
use once_cell::unsync::Lazy;
|
||||||
use ra_db::{FileId, FileRange, SourceDatabaseExt};
|
use ra_db::{FileId, FileRange, SourceDatabaseExt};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
|
@ -123,51 +123,47 @@ impl Definition {
|
||||||
return SearchScope::new(res);
|
return SearchScope::new(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
let vis = self.visibility(db).as_ref().map(|v| v.syntax().to_string()).unwrap_or_default();
|
let vis = self.visibility(db);
|
||||||
|
|
||||||
if vis.as_str() == "pub(super)" {
|
// FIXME:
|
||||||
if let Some(parent_module) = module.parent(db) {
|
// The following logic are wrong that it does not search
|
||||||
let mut res = FxHashMap::default();
|
// for submodules within other files recursively.
|
||||||
let parent_src = parent_module.definition_source(db);
|
|
||||||
let file_id = parent_src.file_id.original_file(db);
|
|
||||||
|
|
||||||
match parent_src.value {
|
if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) {
|
||||||
ModuleSource::Module(m) => {
|
let module: Module = module.into();
|
||||||
let range = Some(m.syntax().text_range());
|
let mut res = FxHashMap::default();
|
||||||
res.insert(file_id, range);
|
let src = module.definition_source(db);
|
||||||
}
|
let file_id = src.file_id.original_file(db);
|
||||||
ModuleSource::SourceFile(_) => {
|
|
||||||
res.insert(file_id, None);
|
match src.value {
|
||||||
res.extend(parent_module.children(db).map(|m| {
|
ModuleSource::Module(m) => {
|
||||||
let src = m.definition_source(db);
|
let range = Some(m.syntax().text_range());
|
||||||
(src.file_id.original_file(db), None)
|
res.insert(file_id, range);
|
||||||
}));
|
}
|
||||||
}
|
ModuleSource::SourceFile(_) => {
|
||||||
|
res.insert(file_id, None);
|
||||||
|
res.extend(module.children(db).map(|m| {
|
||||||
|
let src = m.definition_source(db);
|
||||||
|
(src.file_id.original_file(db), None)
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
return SearchScope::new(res);
|
|
||||||
}
|
}
|
||||||
|
return SearchScope::new(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if vis.as_str() != "" {
|
if let Some(Visibility::Public) = vis {
|
||||||
let source_root_id = db.file_source_root(file_id);
|
let source_root_id = db.file_source_root(file_id);
|
||||||
let source_root = db.source_root(source_root_id);
|
let source_root = db.source_root(source_root_id);
|
||||||
let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
|
let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
// FIXME: add "pub(in path)"
|
let krate = module.krate();
|
||||||
|
for rev_dep in krate.reverse_dependencies(db) {
|
||||||
if vis.as_str() == "pub(crate)" {
|
let root_file = rev_dep.root_file(db);
|
||||||
return SearchScope::new(res);
|
let source_root_id = db.file_source_root(root_file);
|
||||||
}
|
let source_root = db.source_root(source_root_id);
|
||||||
if vis.as_str() == "pub" {
|
res.extend(source_root.walk().map(|id| (id, None)));
|
||||||
let krate = module.krate();
|
|
||||||
for rev_dep in krate.reverse_dependencies(db) {
|
|
||||||
let root_file = rev_dep.root_file(db);
|
|
||||||
let source_root_id = db.file_source_root(root_file);
|
|
||||||
let source_root = db.source_root(source_root_id);
|
|
||||||
res.extend(source_root.walk().map(|id| (id, None)));
|
|
||||||
}
|
|
||||||
return SearchScope::new(res);
|
|
||||||
}
|
}
|
||||||
|
return SearchScope::new(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut res = FxHashMap::default();
|
let mut res = FxHashMap::default();
|
||||||
|
|
Loading…
Reference in a new issue