diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-25 12:25:46 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-25 12:25:46 +0000 |
commit | 8d667bb32ed8460988bf9fe3515a6f8318adb8b0 (patch) | |
tree | 5d41d254dc94ff7d8d20063a08df2b9b133d34d9 /crates/ra_hir_expand/src/lib.rs | |
parent | e2dd17f75b1bb5e1185acff66211e74430177592 (diff) | |
parent | 2adc9a8d5f8f7686a125a478330c67a2d46fba98 (diff) |
Merge #3692
3692: Introduce `MacroDefKind::CustomDerive` r=matklad a=edwin0cheng
This PR introduce a new `MacroDefKind` `CustomDerive`. And use a new `ProcMacroExpander` for its expanding. And the expander is a dummy for now.
Related: #3654
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 6b59ea4c9..86299459f 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -11,6 +11,7 @@ pub mod hygiene; | |||
11 | pub mod diagnostics; | 11 | pub mod diagnostics; |
12 | pub mod builtin_derive; | 12 | pub mod builtin_derive; |
13 | pub mod builtin_macro; | 13 | pub mod builtin_macro; |
14 | pub mod proc_macro; | ||
14 | pub mod quote; | 15 | pub mod quote; |
15 | pub mod eager; | 16 | pub mod eager; |
16 | 17 | ||
@@ -27,6 +28,7 @@ use ra_syntax::{ | |||
27 | use crate::ast_id_map::FileAstId; | 28 | use crate::ast_id_map::FileAstId; |
28 | use crate::builtin_derive::BuiltinDeriveExpander; | 29 | use crate::builtin_derive::BuiltinDeriveExpander; |
29 | use crate::builtin_macro::{BuiltinFnLikeExpander, EagerExpander}; | 30 | use crate::builtin_macro::{BuiltinFnLikeExpander, EagerExpander}; |
31 | use crate::proc_macro::ProcMacroExpander; | ||
30 | 32 | ||
31 | #[cfg(test)] | 33 | #[cfg(test)] |
32 | mod test_db; | 34 | mod test_db; |
@@ -217,6 +219,7 @@ pub enum MacroDefKind { | |||
217 | // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander | 219 | // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander |
218 | BuiltInDerive(BuiltinDeriveExpander), | 220 | BuiltInDerive(BuiltinDeriveExpander), |
219 | BuiltInEager(EagerExpander), | 221 | BuiltInEager(EagerExpander), |
222 | CustomDerive(ProcMacroExpander), | ||
220 | } | 223 | } |
221 | 224 | ||
222 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 225 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -228,21 +231,23 @@ pub struct MacroCallLoc { | |||
228 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 231 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
229 | pub enum MacroCallKind { | 232 | pub enum MacroCallKind { |
230 | FnLike(AstId<ast::MacroCall>), | 233 | FnLike(AstId<ast::MacroCall>), |
231 | Attr(AstId<ast::ModuleItem>), | 234 | Attr(AstId<ast::ModuleItem>, String), |
232 | } | 235 | } |
233 | 236 | ||
234 | impl MacroCallKind { | 237 | impl MacroCallKind { |
235 | pub fn file_id(&self) -> HirFileId { | 238 | pub fn file_id(&self) -> HirFileId { |
236 | match self { | 239 | match self { |
237 | MacroCallKind::FnLike(ast_id) => ast_id.file_id, | 240 | MacroCallKind::FnLike(ast_id) => ast_id.file_id, |
238 | MacroCallKind::Attr(ast_id) => ast_id.file_id, | 241 | MacroCallKind::Attr(ast_id, _) => ast_id.file_id, |
239 | } | 242 | } |
240 | } | 243 | } |
241 | 244 | ||
242 | pub fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { | 245 | pub fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { |
243 | match self { | 246 | match self { |
244 | MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), | 247 | MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), |
245 | MacroCallKind::Attr(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), | 248 | MacroCallKind::Attr(ast_id, _) => { |
249 | ast_id.with_value(ast_id.to_node(db).syntax().clone()) | ||
250 | } | ||
246 | } | 251 | } |
247 | } | 252 | } |
248 | 253 | ||
@@ -251,7 +256,7 @@ impl MacroCallKind { | |||
251 | MacroCallKind::FnLike(ast_id) => { | 256 | MacroCallKind::FnLike(ast_id) => { |
252 | Some(ast_id.to_node(db).token_tree()?.syntax().clone()) | 257 | Some(ast_id.to_node(db).token_tree()?.syntax().clone()) |
253 | } | 258 | } |
254 | MacroCallKind::Attr(ast_id) => Some(ast_id.to_node(db).syntax().clone()), | 259 | MacroCallKind::Attr(ast_id, _) => Some(ast_id.to_node(db).syntax().clone()), |
255 | } | 260 | } |
256 | } | 261 | } |
257 | } | 262 | } |