Skip to content

Commit f4bf750

Browse files
committed
simpler way of grabbing module / trait name
1 parent b0c7ff3 commit f4bf750

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

crates/ide_db/src/symbol_index.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use fst::{self, Streamer};
3737
use hir::{
3838
db::{DefDatabase, HirDatabase},
3939
AdtId, AssocContainerId, AssocItemId, AssocItemLoc, DefHasSource, DefWithBodyId, HasSource,
40-
HirFileId, ImplId, InFile, ItemLoc, ItemTreeNode, Lookup, MacroDef, ModuleDefId, ModuleId,
41-
Semantics, TraitId,
40+
HirFileId, ImplId, InFile, ItemLoc, ItemTreeNode, Lookup, MacroDef, Module, ModuleDefId,
41+
ModuleId, Semantics, TraitId,
4242
};
4343
use rayon::prelude::*;
4444
use rustc_hash::FxHashSet;
@@ -472,8 +472,7 @@ impl<'a> SymbolCollector<'a> {
472472

473473
fn collect_from_module(&mut self, module_id: ModuleId) {
474474
let def_map = module_id.def_map(self.db.upcast());
475-
let module_data = &def_map[module_id.local_id];
476-
let scope = &module_data.scope;
475+
let scope = &def_map[module_id.local_id].scope;
477476

478477
for module_def_id in scope.declarations() {
479478
match module_def_id {
@@ -594,20 +593,15 @@ impl<'a> SymbolCollector<'a> {
594593
T: ItemTreeNode,
595594
<T as ItemTreeNode>::Source: HasName,
596595
{
597-
fn container_name(db: &dyn DefDatabase, container: AssocContainerId) -> Option<SmolStr> {
596+
fn container_name(db: &dyn HirDatabase, container: AssocContainerId) -> Option<SmolStr> {
598597
match container {
599598
AssocContainerId::ModuleId(module_id) => {
600-
let def_map = module_id.def_map(db);
601-
let module_data = &def_map[module_id.local_id];
602-
module_data
603-
.origin
604-
.declaration()
605-
.and_then(|s| s.to_node(db.upcast()).name().map(|n| n.text().into()))
599+
let module = Module::from(module_id);
600+
module.name(db).and_then(|name| name.as_text())
606601
}
607602
AssocContainerId::TraitId(trait_id) => {
608-
let loc = trait_id.lookup(db);
609-
let source = loc.source(db);
610-
source.value.name().map(|n| n.text().into())
603+
let trait_data = db.trait_data(trait_id);
604+
trait_data.name.as_text()
611605
}
612606
AssocContainerId::ImplId(_) => None,
613607
}

0 commit comments

Comments
 (0)