remove ast_editor.rs

This commit is contained in:
Aleksey Kladov 2019-09-30 10:05:12 +03:00
parent 054c53aeb9
commit 05ca252fb5
4 changed files with 16 additions and 59 deletions

View file

@ -4,6 +4,7 @@
use std::{iter, ops::RangeInclusive};
use arrayvec::ArrayVec;
use rustc_hash::FxHashMap;
use crate::{
algo,
@ -216,6 +217,17 @@ fn strip_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
node
}
pub fn replace_descendants<N: AstNode, D: AstNode>(
parent: &N,
replacement_map: impl Iterator<Item = (D, D)>,
) -> N {
let map = replacement_map
.map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into()))
.collect::<FxHashMap<_, _>>();
let new_syntax = algo::replace_descendants(parent.syntax(), &map);
N::cast(new_syntax).unwrap()
}
// Note this is copy-pasted from fmt. It seems like fmt should be a separate
// crate, but basic tree building should be this crate. However, tree building
// might want to call into fmt...