diff options
author | Aleksey Kladov <[email protected]> | 2019-05-04 15:38:09 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-05-04 15:38:09 +0100 |
commit | 5dc384132f7fe6f610ec21e62830ab83f45274a9 (patch) | |
tree | f9b89014aff6dab0353b2134dc5e8cf502f7fc4f /crates/ra_hir/src/ids.rs | |
parent | 8876f44054f57c1f4ee305eb47340609683bd566 (diff) |
introduce macro_arg intermediate query
Currently, when expanding macros, we look at the source code
directly (we invoke ast_id_to_node query via to_node method).
This is less then ideal, because it make us re-expand macros after
every source change.
This commit establishes a salsa-firewall: a query to get macro call's
token tree. Unlike the syntax tree, token tree changes only if we
actually modify the macro itself.
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index b0e9b1f9a..24c5f412b 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -86,11 +86,7 @@ fn parse_macro( | |||
86 | macro_call_id: MacroCallId, | 86 | macro_call_id: MacroCallId, |
87 | ) -> Result<TreeArc<SourceFile>, String> { | 87 | ) -> Result<TreeArc<SourceFile>, String> { |
88 | let loc = macro_call_id.loc(db); | 88 | let loc = macro_call_id.loc(db); |
89 | let macro_call = loc.ast_id.to_node(db); | 89 | let macro_arg = db.macro_arg(macro_call_id).ok_or("Fail to args in to tt::TokenTree")?; |
90 | let (macro_arg, _) = macro_call | ||
91 | .token_tree() | ||
92 | .and_then(mbe::ast_to_token_tree) | ||
93 | .ok_or("Fail to args in to tt::TokenTree")?; | ||
94 | 90 | ||
95 | let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?; | 91 | let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?; |
96 | let tt = macro_rules.expand(¯o_arg).map_err(|err| format!("{:?}", err))?; | 92 | let tt = macro_rules.expand(¯o_arg).map_err(|err| format!("{:?}", err))?; |
@@ -139,6 +135,14 @@ pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<A | |||
139 | Some(Arc::new(rules)) | 135 | Some(Arc::new(rules)) |
140 | } | 136 | } |
141 | 137 | ||
138 | pub(crate) fn macro_arg_query(db: &impl DefDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> { | ||
139 | let loc = id.loc(db); | ||
140 | let macro_call = loc.ast_id.to_node(db); | ||
141 | let arg = macro_call.token_tree()?; | ||
142 | let (tt, _) = mbe::ast_to_token_tree(arg)?; | ||
143 | Some(Arc::new(tt)) | ||
144 | } | ||
145 | |||
142 | macro_rules! impl_intern_key { | 146 | macro_rules! impl_intern_key { |
143 | ($name:ident) => { | 147 | ($name:ident) => { |
144 | impl salsa::InternKey for $name { | 148 | impl salsa::InternKey for $name { |