diff options
author | Aleksey Kladov <[email protected]> | 2019-09-30 08:05:12 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-30 08:05:12 +0100 |
commit | 05ca252fb51bbbf60433bdd3af55ce14bbd66bfd (patch) | |
tree | 3f1b50838de801f487c811df3c9a7e7b0c229ba7 /crates/ra_assists/src/ast_editor.rs | |
parent | 054c53aeb9a9e29d1c06fa183da263037aa62572 (diff) |
remove ast_editor.rs
Diffstat (limited to 'crates/ra_assists/src/ast_editor.rs')
-rw-r--r-- | crates/ra_assists/src/ast_editor.rs | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs deleted file mode 100644 index 69abf28a1..000000000 --- a/crates/ra_assists/src/ast_editor.rs +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | use std::{iter, ops::RangeInclusive}; | ||
2 | |||
3 | use ra_syntax::{ | ||
4 | algo, | ||
5 | ast::{self, TypeBoundsOwner}, | ||
6 | AstNode, SyntaxElement, | ||
7 | }; | ||
8 | use ra_text_edit::TextEditBuilder; | ||
9 | use rustc_hash::FxHashMap; | ||
10 | |||
11 | pub struct AstEditor<N: AstNode> { | ||
12 | original_ast: N, | ||
13 | ast: N, | ||
14 | } | ||
15 | |||
16 | impl<N: AstNode> AstEditor<N> { | ||
17 | pub fn new(node: N) -> AstEditor<N> | ||
18 | where | ||
19 | N: Clone, | ||
20 | { | ||
21 | AstEditor { original_ast: node.clone(), ast: node } | ||
22 | } | ||
23 | |||
24 | pub fn into_text_edit(self, builder: &mut TextEditBuilder) { | ||
25 | algo::diff(&self.original_ast.syntax(), self.ast().syntax()).into_text_edit(builder) | ||
26 | } | ||
27 | |||
28 | pub fn ast(&self) -> &N { | ||
29 | &self.ast | ||
30 | } | ||
31 | |||
32 | pub fn replace_descendants<T: AstNode>( | ||
33 | &mut self, | ||
34 | replacement_map: impl Iterator<Item = (T, T)>, | ||
35 | ) -> &mut Self { | ||
36 | let map = replacement_map | ||
37 | .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into())) | ||
38 | .collect::<FxHashMap<_, _>>(); | ||
39 | let new_syntax = algo::replace_descendants(self.ast.syntax(), &map); | ||
40 | self.ast = N::cast(new_syntax).unwrap(); | ||
41 | self | ||
42 | } | ||
43 | |||
44 | #[must_use] | ||
45 | fn replace_children( | ||
46 | &self, | ||
47 | to_delete: RangeInclusive<SyntaxElement>, | ||
48 | mut to_insert: impl Iterator<Item = SyntaxElement>, | ||
49 | ) -> N { | ||
50 | let new_syntax = algo::replace_children(self.ast().syntax(), to_delete, &mut to_insert); | ||
51 | N::cast(new_syntax).unwrap() | ||
52 | } | ||
53 | } | ||