From cb958cf5fec8b051d16833ac0890cace379ad765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 22 Jul 2020 21:50:37 +0300 Subject: Store macro invocation parameters as text instead of tt --- crates/ra_hir_expand/src/db.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index bf30d7151..e0ad1567f 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs @@ -6,7 +6,7 @@ use mbe::{ExpandResult, MacroRules}; use ra_db::{salsa, SourceDatabase}; use ra_parser::FragmentKind; use ra_prof::profile; -use ra_syntax::{algo::diff, AstNode, Parse, SyntaxKind::*, SyntaxNode}; +use ra_syntax::{algo::diff, AstNode, GreenNode, Parse, SyntaxKind::*, SyntaxNode}; use crate::{ ast_id_map::AstIdMap, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallLoc, EagerMacroId, @@ -72,6 +72,8 @@ pub trait AstDatabase: SourceDatabase { #[salsa::interned] fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId; + fn macro_arg_text(&self, id: MacroCallId) -> Option; + #[salsa::transparent] fn macro_arg(&self, id: MacroCallId) -> Option>; fn macro_def(&self, id: MacroDefId) -> Option>; fn parse_macro(&self, macro_file: MacroFile) @@ -148,10 +150,7 @@ pub(crate) fn macro_def( } } -pub(crate) fn macro_arg( - db: &dyn AstDatabase, - id: MacroCallId, -) -> Option> { +pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option { let id = match id { MacroCallId::LazyMacro(id) => id, MacroCallId::EagerMacro(_id) => { @@ -161,7 +160,15 @@ pub(crate) fn macro_arg( }; let loc = db.lookup_intern_macro(id); let arg = loc.kind.arg(db)?; - let (tt, tmap) = mbe::syntax_node_to_token_tree(&arg)?; + Some(arg.green().clone()) +} + +pub(crate) fn macro_arg( + db: &dyn AstDatabase, + id: MacroCallId, +) -> Option> { + let arg = db.macro_arg_text(id)?; + let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?; Some(Arc::new((tt, tmap))) } -- cgit v1.2.3