aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/lib.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-18 09:47:59 +0000
committerEdwin Cheng <[email protected]>2020-03-25 11:50:12 +0000
commit34dc8d25c1e461cc311d6d4404f74502513cd3ae (patch)
tree00aab26b07c1cd42dfa350eeddc6c41e5bea178b /crates/ra_hir_expand/src/lib.rs
parente2dd17f75b1bb5e1185acff66211e74430177592 (diff)
Add basic custom derive lowering
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r--crates/ra_hir_expand/src/lib.rs13
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..ac1d12252 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -11,6 +11,7 @@ pub mod hygiene;
11pub mod diagnostics; 11pub mod diagnostics;
12pub mod builtin_derive; 12pub mod builtin_derive;
13pub mod builtin_macro; 13pub mod builtin_macro;
14pub mod proc_macro;
14pub mod quote; 15pub mod quote;
15pub mod eager; 16pub mod eager;
16 17
@@ -27,6 +28,7 @@ use ra_syntax::{
27use crate::ast_id_map::FileAstId; 28use crate::ast_id_map::FileAstId;
28use crate::builtin_derive::BuiltinDeriveExpander; 29use crate::builtin_derive::BuiltinDeriveExpander;
29use crate::builtin_macro::{BuiltinFnLikeExpander, EagerExpander}; 30use crate::builtin_macro::{BuiltinFnLikeExpander, EagerExpander};
31use crate::proc_macro::ProcMacroExpander;
30 32
31#[cfg(test)] 33#[cfg(test)]
32mod test_db; 34mod 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 ProcMacro(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)]
229pub enum MacroCallKind { 232pub 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
234impl MacroCallKind { 237impl 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}