diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-03 17:17:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-03 17:17:25 +0100 |
commit | 14153671caaca852c94bd1d0d7f279acb8eb1913 (patch) | |
tree | eb377999a5e8677c210791440b18593f909198e6 /crates/hir/src | |
parent | 7f9c4a59d9a84cd8c734286937439b5cd215be27 (diff) | |
parent | 17565f4deafab800d8d87208cff1e27d028e9b0e (diff) |
Merge #9128
9128: feat: expand procedural attribute macros r=jonas-schievink a=jonas-schievink
This adds experimental support for attribute macros. They can be enabled by setting `rust-analyzer.experimental.procAttrMacros` to `true`.
Known issues:
* Tokens aren't remapped, presumably because we edit the input syntax tree (this causes IDE features to not work inside items with attribute macros on them)
* Macro errors aren't reported correctly
Closes https://github.com/rust-analyzer/rust-analyzer/issues/8971
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8964 / https://github.com/la10736/rstest/issues/120
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/2984
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/5412
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6029
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6687
https://github.com/rust-analyzer/rust-analyzer/issues/6740 is still not fixed – we now expand `#[proc_macro_hack]`, but fail to expand the resulting `proc_macro_call!()` macro.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/lib.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d3ef29db4..b43d61d0e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -534,6 +534,18 @@ impl Module { | |||
534 | Some(derive_name.clone()), | 534 | Some(derive_name.clone()), |
535 | ) | 535 | ) |
536 | } | 536 | } |
537 | MacroCallKind::Attr { ast_id, invoc_attr_index, attr_name, .. } => { | ||
538 | let node = ast_id.to_node(db.upcast()); | ||
539 | let attr = | ||
540 | node.attrs().nth((*invoc_attr_index) as usize).unwrap_or_else( | ||
541 | || panic!("cannot find attribute #{}", invoc_attr_index), | ||
542 | ); | ||
543 | ( | ||
544 | ast_id.file_id, | ||
545 | SyntaxNodePtr::from(AstPtr::new(&attr)), | ||
546 | Some(attr_name.clone()), | ||
547 | ) | ||
548 | } | ||
537 | }; | 549 | }; |
538 | sink.push(UnresolvedProcMacro { | 550 | sink.push(UnresolvedProcMacro { |
539 | file, | 551 | file, |
@@ -558,7 +570,9 @@ impl Module { | |||
558 | let node = ast_id.to_node(db.upcast()); | 570 | let node = ast_id.to_node(db.upcast()); |
559 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) | 571 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) |
560 | } | 572 | } |
561 | MacroCallKind::Derive { ast_id, .. } => { | 573 | MacroCallKind::Derive { ast_id, .. } |
574 | | MacroCallKind::Attr { ast_id, .. } => { | ||
575 | // FIXME: point to the attribute instead, this creates very large diagnostics | ||
562 | let node = ast_id.to_node(db.upcast()); | 576 | let node = ast_id.to_node(db.upcast()); |
563 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) | 577 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) |
564 | } | 578 | } |