From 062f6e3bbeffaa880d7f1c0b59dfad86b40a57a1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 24 Mar 2020 17:03:05 +0100 Subject: Generalise syntax rewriting infrastructure to allow removal of nodes --- crates/ra_ide/src/expand_macro.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index e58526f31..f536ba3e7 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs @@ -3,10 +3,9 @@ use hir::Semantics; use ra_ide_db::RootDatabase; use ra_syntax::{ - algo::{find_node_at_offset, replace_descendants}, - ast, AstNode, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, WalkEvent, T, + algo::{find_node_at_offset, SyntaxRewriter}, + ast, AstNode, NodeOrToken, SyntaxKind, SyntaxNode, WalkEvent, T, }; -use rustc_hash::FxHashMap; use crate::FilePosition; @@ -37,7 +36,7 @@ fn expand_macro_recur( let mut expanded = sema.expand(macro_call)?; let children = expanded.descendants().filter_map(ast::MacroCall::cast); - let mut replaces: FxHashMap = FxHashMap::default(); + let mut rewriter = SyntaxRewriter::default(); for child in children.into_iter() { if let Some(new_node) = expand_macro_recur(sema, &child) { @@ -47,12 +46,13 @@ fn expand_macro_recur( if expanded == *child.syntax() { expanded = new_node; } else { - replaces.insert(child.syntax().clone().into(), new_node.into()); + rewriter.replace(child.syntax(), &new_node) } } } - Some(replace_descendants(&expanded, |n| replaces.get(n).cloned())) + let res = rewriter.rewrite(&expanded); + Some(res) } // FIXME: It would also be cool to share logic here and in the mbe tests, -- cgit v1.2.3