Unnamed repository; edit this file 'description' to name the repository.
container name?
Jake Heinz 2021-11-27
parent a1030b0 · commit 377162c
-rw-r--r--crates/hir/src/lib.rs7
-rw-r--r--crates/ide_db/src/symbol_index.rs24
2 files changed, 24 insertions, 7 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index afa773aaa4..c112b94e01 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -44,9 +44,9 @@ use hir_def::{
nameres,
per_ns::PerNs,
resolver::{HasResolver, Resolver},
- AssocContainerId, AssocItemId, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId,
- FunctionId, GenericDefId, HasModule, ImplId, LifetimeParamId, LocalEnumVariantId, LocalFieldId,
- StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
+ AssocItemId, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, FunctionId, GenericDefId,
+ HasModule, ImplId, LifetimeParamId, LocalEnumVariantId, LocalFieldId, StaticId, StructId,
+ TraitId, TypeAliasId, TypeParamId, UnionId,
};
use hir_expand::{name::name, MacroCallKind, MacroDefId, MacroDefKind};
use hir_ty::{
@@ -114,6 +114,7 @@ pub use {
type_ref::{Mutability, TypeRef},
visibility::Visibility,
AdtId,
+ AssocContainerId,
AssocItemLoc,
ItemLoc,
Lookup,
diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs
index 5bea5837a7..f5f67dcc9b 100644
--- a/crates/ide_db/src/symbol_index.rs
+++ b/crates/ide_db/src/symbol_index.rs
@@ -34,8 +34,8 @@ use base_db::{
};
use fst::{self, Streamer};
use hir::{
- db::DefDatabase, AdtId, AssocItemLoc, DefHasSource, HirFileId, ItemLoc, ItemScope,
- ItemTreeNode, Lookup, ModuleData, ModuleDefId, ModuleId,
+ db::DefDatabase, AdtId, AssocContainerId, AssocItemLoc, DefHasSource, HirFileId, ItemLoc,
+ ItemScope, ItemTreeNode, Lookup, ModuleData, ModuleDefId, ModuleId,
};
use rayon::prelude::*;
use rustc_hash::{FxHashMap, FxHashSet};
@@ -516,12 +516,28 @@ fn collect_symbols_from_item_scope(
let name = name.text().into();
let ptr = SyntaxNodePtr::new(source.value.syntax());
+ let container_name = match loc.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()))
+ }
+ AssocContainerId::TraitId(trait_id) => {
+ let loc = trait_id.lookup(db);
+ let source = loc.source(db);
+ source.value.name().map(|n| n.text().into())
+ }
+ AssocContainerId::ImplId(_) => None,
+ };
+
Some(FileSymbol {
name,
kind,
range: source.value.syntax().text_range(),
- // todo: fill out based on loc.container.
- container_name: None,
+ container_name,
file_id,
name_range: Some(name_range),
ptr,