mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Restructure symbol queries
This commit is contained in:
parent
9c408970ea
commit
e7285507f6
3 changed files with 57 additions and 44 deletions
|
@ -102,21 +102,33 @@ pub struct SymbolCollector<'a> {
|
|||
/// Given a [`ModuleId`] and a [`HirDatabase`], use the DefMap for the module's crate to collect
|
||||
/// all symbols that should be indexed for the given module.
|
||||
impl<'a> SymbolCollector<'a> {
|
||||
pub fn collect(db: &dyn HirDatabase, module: Module) -> Vec<FileSymbol> {
|
||||
let mut symbol_collector = SymbolCollector {
|
||||
pub fn new(db: &'a dyn HirDatabase) -> Self {
|
||||
SymbolCollector {
|
||||
db,
|
||||
symbols: Default::default(),
|
||||
work: Default::default(),
|
||||
current_container_name: None,
|
||||
// The initial work is the root module we're collecting, additional work will
|
||||
// be populated as we traverse the module's definitions.
|
||||
work: vec![SymbolCollectorWork { module_id: module.into(), parent: None }],
|
||||
};
|
||||
|
||||
while let Some(work) = symbol_collector.work.pop() {
|
||||
symbol_collector.do_work(work);
|
||||
}
|
||||
}
|
||||
|
||||
symbol_collector.symbols
|
||||
pub fn collect(&mut self, module: Module) {
|
||||
// The initial work is the root module we're collecting, additional work will
|
||||
// be populated as we traverse the module's definitions.
|
||||
self.work.push(SymbolCollectorWork { module_id: module.into(), parent: None });
|
||||
|
||||
while let Some(work) = self.work.pop() {
|
||||
self.do_work(work);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finish(self) -> Vec<FileSymbol> {
|
||||
self.symbols
|
||||
}
|
||||
|
||||
pub fn collect_module(db: &dyn HirDatabase, module: Module) -> Vec<FileSymbol> {
|
||||
let mut symbol_collector = SymbolCollector::new(db);
|
||||
symbol_collector.collect(module);
|
||||
symbol_collector.finish()
|
||||
}
|
||||
|
||||
fn do_work(&mut self, work: SymbolCollectorWork) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue