mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Only add entries to SourceToDef dynmaps when they come from the same file
This commit is contained in:
parent
0c0142f61a
commit
c90ecc5c26
3 changed files with 125 additions and 76 deletions
|
@ -95,7 +95,7 @@ use hir_def::{
|
|||
GenericDefId, ImplId, LifetimeParamId, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
|
||||
TypeParamId, UnionId, VariantId,
|
||||
};
|
||||
use hir_expand::{name::AsName, AstId, MacroCallId, MacroDefId, MacroDefKind};
|
||||
use hir_expand::{name::AsName, AstId, HirFileId, MacroCallId, MacroDefId, MacroDefKind};
|
||||
use rustc_hash::FxHashMap;
|
||||
use smallvec::SmallVec;
|
||||
use stdx::impl_from;
|
||||
|
@ -106,7 +106,7 @@ use syntax::{
|
|||
|
||||
use crate::{db::HirDatabase, InFile};
|
||||
|
||||
pub(super) type SourceToDefCache = FxHashMap<ChildContainer, DynMap>;
|
||||
pub(super) type SourceToDefCache = FxHashMap<ChildContainer, FxHashMap<HirFileId, DynMap>>;
|
||||
|
||||
pub(super) struct SourceToDefCtx<'a, 'b> {
|
||||
pub(super) db: &'b dyn HirDatabase,
|
||||
|
@ -252,17 +252,18 @@ impl SourceToDefCtx<'_, '_> {
|
|||
|
||||
fn dyn_map<Ast: AstNode + 'static>(&mut self, src: InFile<&Ast>) -> Option<&DynMap> {
|
||||
let container = self.find_container(src.map(|it| it.syntax()))?;
|
||||
Some(self.cache_for(container, src.file_id))
|
||||
}
|
||||
|
||||
fn cache_for(&mut self, container: ChildContainer, file_id: HirFileId) -> &DynMap {
|
||||
let db = self.db;
|
||||
let dyn_map =
|
||||
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
|
||||
Some(dyn_map)
|
||||
let dyn_maps = self.cache.entry(container).or_default();
|
||||
dyn_maps.entry(file_id).or_insert_with(|| container.child_by_source(db, file_id))
|
||||
}
|
||||
|
||||
pub(super) fn type_param_to_def(&mut self, src: InFile<ast::TypeParam>) -> Option<TypeParamId> {
|
||||
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
|
||||
let db = self.db;
|
||||
let dyn_map =
|
||||
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
|
||||
let dyn_map = self.cache_for(container, src.file_id);
|
||||
dyn_map[keys::TYPE_PARAM].get(&src).copied()
|
||||
}
|
||||
|
||||
|
@ -271,9 +272,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||
src: InFile<ast::LifetimeParam>,
|
||||
) -> Option<LifetimeParamId> {
|
||||
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
|
||||
let db = self.db;
|
||||
let dyn_map =
|
||||
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
|
||||
let dyn_map = self.cache_for(container, src.file_id);
|
||||
dyn_map[keys::LIFETIME_PARAM].get(&src).copied()
|
||||
}
|
||||
|
||||
|
@ -282,9 +281,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||
src: InFile<ast::ConstParam>,
|
||||
) -> Option<ConstParamId> {
|
||||
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
|
||||
let db = self.db;
|
||||
let dyn_map =
|
||||
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
|
||||
let dyn_map = self.cache_for(container, src.file_id);
|
||||
dyn_map[keys::CONST_PARAM].get(&src).copied()
|
||||
}
|
||||
|
||||
|
@ -422,17 +419,17 @@ impl_from! {
|
|||
}
|
||||
|
||||
impl ChildContainer {
|
||||
fn child_by_source(self, db: &dyn HirDatabase) -> DynMap {
|
||||
fn child_by_source(self, db: &dyn HirDatabase, file_id: HirFileId) -> DynMap {
|
||||
let db = db.upcast();
|
||||
match self {
|
||||
ChildContainer::DefWithBodyId(it) => it.child_by_source(db),
|
||||
ChildContainer::ModuleId(it) => it.child_by_source(db),
|
||||
ChildContainer::TraitId(it) => it.child_by_source(db),
|
||||
ChildContainer::ImplId(it) => it.child_by_source(db),
|
||||
ChildContainer::EnumId(it) => it.child_by_source(db),
|
||||
ChildContainer::VariantId(it) => it.child_by_source(db),
|
||||
ChildContainer::DefWithBodyId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::ModuleId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::TraitId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::ImplId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::EnumId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::VariantId(it) => it.child_by_source(db, file_id),
|
||||
ChildContainer::TypeAliasId(_) => DynMap::default(),
|
||||
ChildContainer::GenericDefId(it) => it.child_by_source(db),
|
||||
ChildContainer::GenericDefId(it) => it.child_by_source(db, file_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue