diff options
Diffstat (limited to 'crates/ra_editor/src/code_actions.rs')
-rw-r--r-- | crates/ra_editor/src/code_actions.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs index b0f0d8f1d..216d592ff 100644 --- a/crates/ra_editor/src/code_actions.rs +++ b/crates/ra_editor/src/code_actions.rs | |||
@@ -1,12 +1,11 @@ | |||
1 | use join_to_string::join; | 1 | use join_to_string::join; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | File, TextUnit, TextRange, | 4 | File, TextUnit, TextRange, Direction, |
5 | ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, | 5 | ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner}, |
6 | SyntaxKind::{COMMA, WHITESPACE}, | 6 | SyntaxKind::{COMMA, WHITESPACE}, |
7 | SyntaxNodeRef, | 7 | SyntaxNodeRef, |
8 | algo::{ | 8 | algo::{ |
9 | Direction, siblings, | ||
10 | find_leaf_at_offset, | 9 | find_leaf_at_offset, |
11 | find_covering_node, | 10 | find_covering_node, |
12 | }, | 11 | }, |
@@ -24,12 +23,12 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() | |||
24 | let syntax = file.syntax(); | 23 | let syntax = file.syntax(); |
25 | 24 | ||
26 | let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; | 25 | let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; |
27 | let left = non_trivia_sibling(comma, Direction::Backward)?; | 26 | let prev = non_trivia_sibling(comma, Direction::Prev)?; |
28 | let right = non_trivia_sibling(comma, Direction::Forward)?; | 27 | let next = non_trivia_sibling(comma, Direction::Next)?; |
29 | Some(move || { | 28 | Some(move || { |
30 | let mut edit = EditBuilder::new(); | 29 | let mut edit = EditBuilder::new(); |
31 | edit.replace(left.range(), right.text().to_string()); | 30 | edit.replace(prev.range(), next.text().to_string()); |
32 | edit.replace(right.range(), left.text().to_string()); | 31 | edit.replace(next.range(), prev.text().to_string()); |
33 | LocalEdit { | 32 | LocalEdit { |
34 | edit: edit.finish(), | 33 | edit: edit.finish(), |
35 | cursor_position: None, | 34 | cursor_position: None, |
@@ -129,7 +128,7 @@ pub fn introduce_variable<'a>(file: &'a File, range: TextRange) -> Option<impl F | |||
129 | } | 128 | } |
130 | 129 | ||
131 | fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { | 130 | fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { |
132 | siblings(node, direction) | 131 | node.siblings(direction) |
133 | .skip(1) | 132 | .skip(1) |
134 | .find(|node| !node.kind().is_trivia()) | 133 | .find(|node| !node.kind().is_trivia()) |
135 | } | 134 | } |