From 33e747d786e588ab61133fe2c0fb6341826e2cea Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 7 Jun 2021 16:05:36 +0200 Subject: Make "expand macro" command work with attribute macros --- crates/hir/src/semantics.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/hir') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 0d55e4a3e..920e18208 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -117,6 +117,12 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { pub fn expand(&self, macro_call: &ast::MacroCall) -> Option { self.imp.expand(macro_call) } + + /// If `item` has an attribute macro attached to it, expands it. + pub fn expand_attr_macro(&self, item: &ast::Item) -> Option { + self.imp.expand_attr_macro(item) + } + pub fn speculative_expand( &self, actual_macro_call: &ast::MacroCall, @@ -332,6 +338,16 @@ impl<'db> SemanticsImpl<'db> { Some(node) } + fn expand_attr_macro(&self, item: &ast::Item) -> Option { + let sa = self.analyze(item.syntax()); + let src = InFile::new(sa.file_id, item.clone()); + let macro_call_id = self.with_ctx(|ctx| ctx.item_to_macro_call(src))?; + let file_id = macro_call_id.as_file(); + let node = self.db.parse_or_expand(file_id)?; + self.cache(node.clone(), file_id); + Some(node) + } + fn speculative_expand( &self, actual_macro_call: &ast::MacroCall, -- cgit v1.2.3