mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
remove ast_editor.rs
This commit is contained in:
parent
054c53aeb9
commit
05ca252fb5
4 changed files with 16 additions and 59 deletions
|
@ -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...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue