diff options
author | Jonas Schievink <[email protected]> | 2021-06-07 15:05:36 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-06-07 15:05:36 +0100 |
commit | 33e747d786e588ab61133fe2c0fb6341826e2cea (patch) | |
tree | d892ce322c13fff532d1c50c5803148b276a4540 /crates/hir/src | |
parent | 8d87f9b298f41b8eb1e9fa0481c5092c1c136ef9 (diff) |
Make "expand macro" command work with attribute macros
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/semantics.rs | 16 |
1 files changed, 16 insertions, 0 deletions
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> { | |||
117 | pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> { | 117 | pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> { |
118 | self.imp.expand(macro_call) | 118 | self.imp.expand(macro_call) |
119 | } | 119 | } |
120 | |||
121 | /// If `item` has an attribute macro attached to it, expands it. | ||
122 | pub fn expand_attr_macro(&self, item: &ast::Item) -> Option<SyntaxNode> { | ||
123 | self.imp.expand_attr_macro(item) | ||
124 | } | ||
125 | |||
120 | pub fn speculative_expand( | 126 | pub fn speculative_expand( |
121 | &self, | 127 | &self, |
122 | actual_macro_call: &ast::MacroCall, | 128 | actual_macro_call: &ast::MacroCall, |
@@ -332,6 +338,16 @@ impl<'db> SemanticsImpl<'db> { | |||
332 | Some(node) | 338 | Some(node) |
333 | } | 339 | } |
334 | 340 | ||
341 | fn expand_attr_macro(&self, item: &ast::Item) -> Option<SyntaxNode> { | ||
342 | let sa = self.analyze(item.syntax()); | ||
343 | let src = InFile::new(sa.file_id, item.clone()); | ||
344 | let macro_call_id = self.with_ctx(|ctx| ctx.item_to_macro_call(src))?; | ||
345 | let file_id = macro_call_id.as_file(); | ||
346 | let node = self.db.parse_or_expand(file_id)?; | ||
347 | self.cache(node.clone(), file_id); | ||
348 | Some(node) | ||
349 | } | ||
350 | |||
335 | fn speculative_expand( | 351 | fn speculative_expand( |
336 | &self, | 352 | &self, |
337 | actual_macro_call: &ast::MacroCall, | 353 | actual_macro_call: &ast::MacroCall, |