From 1465cc0c4feb52958d3281f066a663e0a52ed67e Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 2 Mar 2020 14:05:15 +0800 Subject: Implement concat macro --- crates/ra_hir_def/src/lib.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index c9b14d0c8..a3d617e1f 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -47,8 +47,8 @@ mod marks; use std::hash::Hash; use hir_expand::{ - ast_id_map::FileAstId, db::AstDatabase, hygiene::Hygiene, AstId, HirFileId, InFile, - MacroCallId, MacroCallKind, MacroDefId, + ast_id_map::FileAstId, db::AstDatabase, eager::expand_eager_macro, hygiene::Hygiene, AstId, + HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, }; use ra_arena::{impl_arena_id, RawId}; use ra_db::{impl_intern_key, salsa, CrateId}; @@ -459,8 +459,21 @@ impl AsMacroCall for AstIdWithPath { db: &impl AstDatabase, resolver: impl Fn(path::ModPath) -> Option, ) -> Option { - let def = resolver(self.path.clone())?; - Some(def.as_call_id(db, MacroCallKind::FnLike(self.ast_id))) + let def: MacroDefId = resolver(self.path.clone())?; + + if let MacroDefKind::BuiltInEager(_) = def.kind { + let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db)); + let hygiene = Hygiene::new(db, self.ast_id.file_id); + + Some( + expand_eager_macro(db, macro_call, def, &|path: ast::Path| { + resolver(path::ModPath::from_src(path, &hygiene)?) + })? + .into(), + ) + } else { + Some(def.as_lazy_macro(db, MacroCallKind::FnLike(self.ast_id)).into()) + } } } @@ -471,6 +484,6 @@ impl AsMacroCall for AstIdWithPath { resolver: impl Fn(path::ModPath) -> Option, ) -> Option { let def = resolver(self.path.clone())?; - Some(def.as_call_id(db, MacroCallKind::Attr(self.ast_id))) + Some(def.as_lazy_macro(db, MacroCallKind::Attr(self.ast_id)).into()) } } -- cgit v1.2.3