aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-30 08:05:12 +0100
committerAleksey Kladov <[email protected]>2019-09-30 08:05:12 +0100
commit05ca252fb51bbbf60433bdd3af55ce14bbd66bfd (patch)
tree3f1b50838de801f487c811df3c9a7e7b0c229ba7 /crates/ra_syntax/src
parent054c53aeb9a9e29d1c06fa183da263037aa62572 (diff)
remove ast_editor.rs
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 9d0fd1383..d0857d88b 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -4,6 +4,7 @@
4use std::{iter, ops::RangeInclusive}; 4use std::{iter, ops::RangeInclusive};
5 5
6use arrayvec::ArrayVec; 6use arrayvec::ArrayVec;
7use rustc_hash::FxHashMap;
7 8
8use crate::{ 9use crate::{
9 algo, 10 algo,
@@ -216,6 +217,17 @@ fn strip_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
216 node 217 node
217} 218}
218 219
220pub fn replace_descendants<N: AstNode, D: AstNode>(
221 parent: &N,
222 replacement_map: impl Iterator<Item = (D, D)>,
223) -> N {
224 let map = replacement_map
225 .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into()))
226 .collect::<FxHashMap<_, _>>();
227 let new_syntax = algo::replace_descendants(parent.syntax(), &map);
228 N::cast(new_syntax).unwrap()
229}
230
219// Note this is copy-pasted from fmt. It seems like fmt should be a separate 231// Note this is copy-pasted from fmt. It seems like fmt should be a separate
220// crate, but basic tree building should be this crate. However, tree building 232// crate, but basic tree building should be this crate. However, tree building
221// might want to call into fmt... 233// might want to call into fmt...