aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/ast/edit.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 3037f2715..d88a0cf4b 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -23,7 +23,7 @@ impl ast::BinExpr {
23 pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> { 23 pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> {
24 let op_node: SyntaxElement = self.op_details()?.0.into(); 24 let op_node: SyntaxElement = self.op_details()?.0.into();
25 let to_insert: Option<SyntaxElement> = Some(make::token(op).into()); 25 let to_insert: Option<SyntaxElement> = Some(make::token(op).into());
26 Some(replace_children(self, single_node(op_node), to_insert.into_iter())) 26 Some(replace_children(self, single_node(op_node), to_insert))
27 } 27 }
28} 28}
29 29
@@ -39,10 +39,10 @@ impl ast::FnDef {
39 } else { 39 } else {
40 to_insert.push(make::tokens::single_space().into()); 40 to_insert.push(make::tokens::single_space().into());
41 to_insert.push(body.syntax().clone().into()); 41 to_insert.push(body.syntax().clone().into());
42 return insert_children(self, InsertPosition::Last, to_insert.into_iter()); 42 return insert_children(self, InsertPosition::Last, to_insert);
43 }; 43 };
44 to_insert.push(body.syntax().clone().into()); 44 to_insert.push(body.syntax().clone().into());
45 replace_children(self, single_node(old_body_or_semi), to_insert.into_iter()) 45 replace_children(self, single_node(old_body_or_semi), to_insert)
46 } 46 }
47} 47}
48 48
@@ -75,7 +75,7 @@ impl ast::ItemList {
75 let ws = tokens::WsBuilder::new(&format!("\n{}", indent)); 75 let ws = tokens::WsBuilder::new(&format!("\n{}", indent));
76 let to_insert: ArrayVec<[SyntaxElement; 2]> = 76 let to_insert: ArrayVec<[SyntaxElement; 2]> =
77 [ws.ws().into(), item.syntax().clone().into()].into(); 77 [ws.ws().into(), item.syntax().clone().into()].into();
78 insert_children(self, position, to_insert.into_iter()) 78 insert_children(self, position, to_insert)
79 } 79 }
80 80
81 fn l_curly(&self) -> Option<SyntaxElement> { 81 fn l_curly(&self) -> Option<SyntaxElement> {
@@ -184,7 +184,7 @@ impl ast::RecordFieldList {
184 InsertPosition::After(anchor) => after_field!(anchor), 184 InsertPosition::After(anchor) => after_field!(anchor),
185 }; 185 };
186 186
187 insert_children(self, position, to_insert.iter().cloned()) 187 insert_children(self, position, to_insert)
188 } 188 }
189 189
190 fn l_curly(&self) -> Option<SyntaxElement> { 190 fn l_curly(&self) -> Option<SyntaxElement> {
@@ -228,9 +228,10 @@ fn strip_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
228#[must_use] 228#[must_use]
229pub fn replace_descendants<N: AstNode, D: AstNode>( 229pub fn replace_descendants<N: AstNode, D: AstNode>(
230 parent: &N, 230 parent: &N,
231 replacement_map: impl Iterator<Item = (D, D)>, 231 replacement_map: impl IntoIterator<Item = (D, D)>,
232) -> N { 232) -> N {
233 let map = replacement_map 233 let map = replacement_map
234 .into_iter()
234 .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into())) 235 .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into()))
235 .collect::<FxHashMap<SyntaxElement, _>>(); 236 .collect::<FxHashMap<SyntaxElement, _>>();
236 let new_syntax = algo::replace_descendants(parent.syntax(), &|n| map.get(n).cloned()); 237 let new_syntax = algo::replace_descendants(parent.syntax(), &|n| map.get(n).cloned());
@@ -344,9 +345,9 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
344fn insert_children<N: AstNode>( 345fn insert_children<N: AstNode>(
345 parent: &N, 346 parent: &N,
346 position: InsertPosition<SyntaxElement>, 347 position: InsertPosition<SyntaxElement>,
347 mut to_insert: impl Iterator<Item = SyntaxElement>, 348 to_insert: impl IntoIterator<Item = SyntaxElement>,
348) -> N { 349) -> N {
349 let new_syntax = algo::insert_children(parent.syntax(), position, &mut to_insert); 350 let new_syntax = algo::insert_children(parent.syntax(), position, &mut to_insert.into_iter());
350 N::cast(new_syntax).unwrap() 351 N::cast(new_syntax).unwrap()
351} 352}
352 353
@@ -359,9 +360,10 @@ fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElemen
359fn replace_children<N: AstNode>( 360fn replace_children<N: AstNode>(
360 parent: &N, 361 parent: &N,
361 to_replace: RangeInclusive<SyntaxElement>, 362 to_replace: RangeInclusive<SyntaxElement>,
362 mut to_insert: impl Iterator<Item = SyntaxElement>, 363 to_insert: impl IntoIterator<Item = SyntaxElement>,
363) -> N { 364) -> N {
364 let new_syntax = algo::replace_children(parent.syntax(), to_replace, &mut to_insert); 365 let new_syntax =
366 algo::replace_children(parent.syntax(), to_replace, &mut to_insert.into_iter());
365 N::cast(new_syntax).unwrap() 367 N::cast(new_syntax).unwrap()
366} 368}
367 369