From c05a1a6e37156b956380d57049a72cfe6f21095d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 18 Mar 2021 16:11:18 +0100 Subject: Store an `AstId` for procedural macros --- crates/hir/src/has_source.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'crates/hir/src/has_source.rs') diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 5b22ab58b..d57fad9ed 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -6,7 +6,7 @@ use hir_def::{ src::{HasChildSource, HasSource as _}, Lookup, VariantId, }; -use hir_expand::InFile; +use hir_expand::{InFile, MacroDefKind}; use syntax::ast; use crate::{ @@ -111,10 +111,17 @@ impl HasSource for TypeAlias { } } impl HasSource for MacroDef { - type Ast = ast::Macro; + type Ast = Either; fn source(self, db: &dyn HirDatabase) -> Option> { - let ast_id = self.id.ast_id()?; - Some(InFile { file_id: ast_id.file_id, value: ast_id.to_node(db.upcast()) }) + Some(match &self.id.kind { + MacroDefKind::Declarative(id) + | MacroDefKind::BuiltIn(_, id) + | MacroDefKind::BuiltInDerive(_, id) + | MacroDefKind::BuiltInEager(_, id) => { + id.with_value(Either::Left(id.to_node(db.upcast()))) + } + MacroDefKind::ProcMacro(_, id) => id.map(|_| Either::Right(id.to_node(db.upcast()))), + }) } } impl HasSource for Impl { -- cgit v1.2.3