mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
recursively search submodules
This commit is contained in:
parent
c575da1609
commit
8ef9703740
1 changed files with 22 additions and 18 deletions
|
@ -124,29 +124,33 @@ impl Definition {
|
||||||
|
|
||||||
let vis = self.visibility(db);
|
let vis = self.visibility(db);
|
||||||
|
|
||||||
// FIXME:
|
|
||||||
// The following logic are wrong that it does not search
|
|
||||||
// for submodules within other files recursively.
|
|
||||||
|
|
||||||
if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) {
|
if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) {
|
||||||
let module: Module = module.into();
|
let module: Module = module.into();
|
||||||
let mut res = FxHashMap::default();
|
let mut res = FxHashMap::default();
|
||||||
let src = module.definition_source(db);
|
|
||||||
let file_id = src.file_id.original_file(db);
|
|
||||||
|
|
||||||
match src.value {
|
let mut to_visit = vec![module];
|
||||||
ModuleSource::Module(m) => {
|
let mut is_first = true;
|
||||||
let range = Some(m.syntax().text_range());
|
while let Some(module) = to_visit.pop() {
|
||||||
res.insert(file_id, range);
|
let src = module.definition_source(db);
|
||||||
}
|
let file_id = src.file_id.original_file(db);
|
||||||
ModuleSource::SourceFile(_) => {
|
match src.value {
|
||||||
res.insert(file_id, None);
|
ModuleSource::Module(m) => {
|
||||||
res.extend(module.children(db).map(|m| {
|
if is_first {
|
||||||
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);
|
||||||
}));
|
} else {
|
||||||
}
|
// We have already added the enclosing file to the search scope,
|
||||||
|
// so do nothing.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ModuleSource::SourceFile(_) => {
|
||||||
|
res.insert(file_id, None);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
is_first = false;
|
||||||
|
to_visit.extend(module.children(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
return SearchScope::new(res);
|
return SearchScope::new(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue