Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/semantics.rs')
| -rw-r--r-- | crates/hir/src/semantics.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 02cfeb361c..2cf63efff8 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -10,7 +10,7 @@ use hir_def::{ resolver::{self, HasResolver, Resolver, TypeNs}, AsMacroCall, FunctionId, TraitId, VariantId, }; -use hir_expand::{name::AsName, ExpansionInfo}; +use hir_expand::{name::AsName, ExpansionInfo, MacroCallLoc}; use hir_ty::{associated_type_shorthand_candidates, Interner}; use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; @@ -160,6 +160,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.imp.expand_attr_macro(item) } + pub fn resolve_derive_macro(&self, derive: &ast::Attr) -> Option<Vec<MacroDef>> { + self.imp.resolve_derive_macro(derive) + } + pub fn expand_derive_macro(&self, derive: &ast::Attr) -> Option<Vec<SyntaxNode>> { self.imp.expand_derive_macro(derive) } @@ -443,6 +447,25 @@ impl<'db> SemanticsImpl<'db> { Some(node) } + fn resolve_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<MacroDef>> { + let item = attr.syntax().parent().and_then(ast::Item::cast)?; + let file_id = self.find_file(item.syntax()).file_id; + let item = InFile::new(file_id, &item); + let src = InFile::new(file_id, attr.clone()); + self.with_ctx(|ctx| { + let macro_call_ids = ctx.attr_to_derive_macro_call(item, src)?; + + let res = macro_call_ids + .iter() + .map(|&call| { + let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call); + MacroDef { id: loc.def } + }) + .collect(); + Some(res) + }) + } + fn expand_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<SyntaxNode>> { let item = attr.syntax().parent().and_then(ast::Item::cast)?; let file_id = self.find_file(item.syntax()).file_id; |