simpler way of grabbing module / trait name
This commit is contained in:
parent
b0c7ff39b8
commit
f4bf750016
1 changed files with 8 additions and 14 deletions
|
@ -37,8 +37,8 @@ use fst::{self, Streamer};
|
||||||
use hir::{
|
use hir::{
|
||||||
db::{DefDatabase, HirDatabase},
|
db::{DefDatabase, HirDatabase},
|
||||||
AdtId, AssocContainerId, AssocItemId, AssocItemLoc, DefHasSource, DefWithBodyId, HasSource,
|
AdtId, AssocContainerId, AssocItemId, AssocItemLoc, DefHasSource, DefWithBodyId, HasSource,
|
||||||
HirFileId, ImplId, InFile, ItemLoc, ItemTreeNode, Lookup, MacroDef, ModuleDefId, ModuleId,
|
HirFileId, ImplId, InFile, ItemLoc, ItemTreeNode, Lookup, MacroDef, Module, ModuleDefId,
|
||||||
Semantics, TraitId,
|
ModuleId, Semantics, TraitId,
|
||||||
};
|
};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
@ -472,8 +472,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
|
|
||||||
fn collect_from_module(&mut self, module_id: ModuleId) {
|
fn collect_from_module(&mut self, module_id: ModuleId) {
|
||||||
let def_map = module_id.def_map(self.db.upcast());
|
let def_map = module_id.def_map(self.db.upcast());
|
||||||
let module_data = &def_map[module_id.local_id];
|
let scope = &def_map[module_id.local_id].scope;
|
||||||
let scope = &module_data.scope;
|
|
||||||
|
|
||||||
for module_def_id in scope.declarations() {
|
for module_def_id in scope.declarations() {
|
||||||
match module_def_id {
|
match module_def_id {
|
||||||
|
@ -594,20 +593,15 @@ impl<'a> SymbolCollector<'a> {
|
||||||
T: ItemTreeNode,
|
T: ItemTreeNode,
|
||||||
<T as ItemTreeNode>::Source: HasName,
|
<T as ItemTreeNode>::Source: HasName,
|
||||||
{
|
{
|
||||||
fn container_name(db: &dyn DefDatabase, container: AssocContainerId) -> Option<SmolStr> {
|
fn container_name(db: &dyn HirDatabase, container: AssocContainerId) -> Option<SmolStr> {
|
||||||
match container {
|
match container {
|
||||||
AssocContainerId::ModuleId(module_id) => {
|
AssocContainerId::ModuleId(module_id) => {
|
||||||
let def_map = module_id.def_map(db);
|
let module = Module::from(module_id);
|
||||||
let module_data = &def_map[module_id.local_id];
|
module.name(db).and_then(|name| name.as_text())
|
||||||
module_data
|
|
||||||
.origin
|
|
||||||
.declaration()
|
|
||||||
.and_then(|s| s.to_node(db.upcast()).name().map(|n| n.text().into()))
|
|
||||||
}
|
}
|
||||||
AssocContainerId::TraitId(trait_id) => {
|
AssocContainerId::TraitId(trait_id) => {
|
||||||
let loc = trait_id.lookup(db);
|
let trait_data = db.trait_data(trait_id);
|
||||||
let source = loc.source(db);
|
trait_data.name.as_text()
|
||||||
source.value.name().map(|n| n.text().into())
|
|
||||||
}
|
}
|
||||||
AssocContainerId::ImplId(_) => None,
|
AssocContainerId::ImplId(_) => None,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue