From 8d87f9b298f41b8eb1e9fa0481c5092c1c136ef9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 6 Jun 2021 15:51:05 +0200 Subject: Handle attribute macros in `descend_into_macros` --- crates/hir/src/semantics/source_to_def.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'crates/hir/src/semantics/source_to_def.rs') diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 9a5a2255f..22e196196 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -10,7 +10,7 @@ use hir_def::{ ImplId, LifetimeParamId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, }; -use hir_expand::{name::AsName, AstId, MacroDefKind}; +use hir_expand::{name::AsName, AstId, MacroCallId, MacroDefKind}; use rustc_hash::FxHashMap; use smallvec::SmallVec; use stdx::impl_from; @@ -145,16 +145,25 @@ impl SourceToDefCtx<'_, '_> { Some((container, label_id)) } + pub(super) fn item_to_macro_call(&mut self, src: InFile) -> Option { + let map = self.dyn_map(src.as_ref())?; + map[keys::ATTR_MACRO].get(&src).copied() + } + fn to_def( &mut self, src: InFile, key: Key, ) -> Option { - let container = self.find_container(src.as_ref().map(|it| it.syntax()))?; + self.dyn_map(src.as_ref())?[key].get(&src).copied() + } + + fn dyn_map(&mut self, src: InFile<&Ast>) -> Option<&DynMap> { + let container = self.find_container(src.map(|it| it.syntax()))?; let db = self.db; let dyn_map = &*self.cache.entry(container).or_insert_with(|| container.child_by_source(db)); - dyn_map[key].get(&src).copied() + Some(dyn_map) } pub(super) fn type_param_to_def(&mut self, src: InFile) -> Option { -- cgit v1.2.3