From f4bf750016c4c51b0ec1f1b0e6e2fe25578796f3 Mon Sep 17 00:00:00 2001 From: Jake Heinz Date: Tue, 30 Nov 2021 08:24:07 +0000 Subject: [PATCH] simpler way of grabbing module / trait name --- crates/ide_db/src/symbol_index.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index f2629f69a0d..cc2b2bbb7b8 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs @@ -37,8 +37,8 @@ use hir::{ db::{DefDatabase, HirDatabase}, AdtId, AssocContainerId, AssocItemId, AssocItemLoc, DefHasSource, DefWithBodyId, HasSource, - HirFileId, ImplId, InFile, ItemLoc, ItemTreeNode, Lookup, MacroDef, ModuleDefId, ModuleId, - Semantics, TraitId, + HirFileId, ImplId, InFile, ItemLoc, ItemTreeNode, Lookup, MacroDef, Module, ModuleDefId, + ModuleId, Semantics, TraitId, }; use rayon::prelude::*; use rustc_hash::FxHashSet; @@ -472,8 +472,7 @@ fn do_work(&mut self, work: SymbolCollectorWork) { fn collect_from_module(&mut self, module_id: ModuleId) { let def_map = module_id.def_map(self.db.upcast()); - let module_data = &def_map[module_id.local_id]; - let scope = &module_data.scope; + let scope = &def_map[module_id.local_id].scope; for module_def_id in scope.declarations() { match module_def_id { @@ -594,20 +593,15 @@ fn push_decl_assoc(&mut self, id: L, kind: FileSymbolKind) T: ItemTreeNode, ::Source: HasName, { - fn container_name(db: &dyn DefDatabase, container: AssocContainerId) -> Option { + fn container_name(db: &dyn HirDatabase, container: AssocContainerId) -> Option { match container { AssocContainerId::ModuleId(module_id) => { - let def_map = module_id.def_map(db); - let module_data = &def_map[module_id.local_id]; - module_data - .origin - .declaration() - .and_then(|s| s.to_node(db.upcast()).name().map(|n| n.text().into())) + let module = Module::from(module_id); + module.name(db).and_then(|name| name.as_text()) } AssocContainerId::TraitId(trait_id) => { - let loc = trait_id.lookup(db); - let source = loc.source(db); - source.value.name().map(|n| n.text().into()) + let trait_data = db.trait_data(trait_id); + trait_data.name.as_text() } AssocContainerId::ImplId(_) => None, }