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);
|
||||
|
||||
// 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()) {
|
||||
let module: Module = module.into();
|
||||
let mut res = FxHashMap::default();
|
||||
|
||||
let mut to_visit = vec![module];
|
||||
let mut is_first = true;
|
||||
while let Some(module) = to_visit.pop() {
|
||||
let src = module.definition_source(db);
|
||||
let file_id = src.file_id.original_file(db);
|
||||
|
||||
match src.value {
|
||||
ModuleSource::Module(m) => {
|
||||
if is_first {
|
||||
let range = Some(m.syntax().text_range());
|
||||
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);
|
||||
res.extend(module.children(db).map(|m| {
|
||||
let src = m.definition_source(db);
|
||||
(src.file_id.original_file(db), None)
|
||||
}));
|
||||
}
|
||||
};
|
||||
is_first = false;
|
||||
to_visit.extend(module.children(db));
|
||||
}
|
||||
|
||||
return SearchScope::new(res);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue