mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Auto merge of #14715 - Veykril:symbol-index, r=Veykril
Refactor symbol index Closes https://github.com/rust-lang/rust-analyzer/issues/14677 instead of eagerly fetching the source data in symbol index we do it lazily now, this shouldn't make it much more expensive as we had to parse the source most of the time anyways even after fetching.
This commit is contained in:
commit
94ac1cdbf5
13 changed files with 422 additions and 684 deletions
|
@ -51,7 +51,7 @@ use hir_def::{
|
|||
per_ns::PerNs,
|
||||
resolver::{HasResolver, Resolver},
|
||||
src::HasSource as _,
|
||||
AdtId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId,
|
||||
AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId,
|
||||
EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
||||
LocalEnumVariantId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId,
|
||||
TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
|
||||
|
@ -119,11 +119,9 @@ pub use {
|
|||
path::{ModPath, PathKind},
|
||||
type_ref::{Mutability, TypeRef},
|
||||
visibility::Visibility,
|
||||
// FIXME: This is here since it is input of a method in `HirWrite`
|
||||
// and things outside of hir need to implement that trait. We probably
|
||||
// should move whole `hir_ty::display` to this crate so we will become
|
||||
// able to use `ModuleDef` or `Definition` instead of `ModuleDefId`.
|
||||
ModuleDefId,
|
||||
// FIXME: This is here since some queries take it as input that are used
|
||||
// outside of hir.
|
||||
{AdtId, ModuleDefId},
|
||||
},
|
||||
hir_expand::{
|
||||
attrs::Attr,
|
||||
|
@ -4429,3 +4427,90 @@ impl HasCrate for Module {
|
|||
Module::krate(*self)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasContainer {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer;
|
||||
}
|
||||
|
||||
impl HasContainer for Module {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
// FIXME: handle block expressions as modules (their parent is in a different DefMap)
|
||||
let def_map = self.id.def_map(db.upcast());
|
||||
match def_map[self.id.local_id].parent {
|
||||
Some(parent_id) => ItemContainer::Module(Module { id: def_map.module_id(parent_id) }),
|
||||
None => ItemContainer::Crate(def_map.krate()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Function {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
container_id_to_hir(self.id.lookup(db.upcast()).container)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Struct {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
ItemContainer::Module(Module { id: self.id.lookup(db.upcast()).container })
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Union {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
ItemContainer::Module(Module { id: self.id.lookup(db.upcast()).container })
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Enum {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
ItemContainer::Module(Module { id: self.id.lookup(db.upcast()).container })
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for TypeAlias {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
container_id_to_hir(self.id.lookup(db.upcast()).container)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Const {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
container_id_to_hir(self.id.lookup(db.upcast()).container)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Static {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
container_id_to_hir(self.id.lookup(db.upcast()).container)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for Trait {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
ItemContainer::Module(Module { id: self.id.lookup(db.upcast()).container })
|
||||
}
|
||||
}
|
||||
|
||||
impl HasContainer for TraitAlias {
|
||||
fn container(&self, db: &dyn HirDatabase) -> ItemContainer {
|
||||
ItemContainer::Module(Module { id: self.id.lookup(db.upcast()).container })
|
||||
}
|
||||
}
|
||||
|
||||
fn container_id_to_hir(c: ItemContainerId) -> ItemContainer {
|
||||
match c {
|
||||
ItemContainerId::ExternBlockId(_id) => ItemContainer::ExternBlock(),
|
||||
ItemContainerId::ModuleId(id) => ItemContainer::Module(Module { id }),
|
||||
ItemContainerId::ImplId(id) => ItemContainer::Impl(Impl { id }),
|
||||
ItemContainerId::TraitId(id) => ItemContainer::Trait(Trait { id }),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum ItemContainer {
|
||||
Trait(Trait),
|
||||
Impl(Impl),
|
||||
Module(Module),
|
||||
ExternBlock(),
|
||||
Crate(CrateId),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue