diff options
Diffstat (limited to 'crates/ra_editor')
-rw-r--r-- | crates/ra_editor/src/code_actions.rs | 13 | ||||
-rw-r--r-- | crates/ra_editor/src/extend_selection.rs | 16 | ||||
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 4 |
3 files changed, 16 insertions, 17 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 | } |
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index 2f8a04b2b..b00a457b9 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_syntax::{ | 1 | use ra_syntax::{ |
2 | File, TextRange, SyntaxNodeRef, TextUnit, | 2 | File, TextRange, SyntaxNodeRef, TextUnit, Direction, |
3 | SyntaxKind::*, | 3 | SyntaxKind::*, |
4 | algo::{find_leaf_at_offset, LeafAtOffset, find_covering_node, Direction, siblings}, | 4 | algo::{find_leaf_at_offset, LeafAtOffset, find_covering_node}, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> { | 7 | pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> { |
@@ -71,12 +71,12 @@ fn pick_best<'a>(l: SyntaxNodeRef<'a>, r: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a | |||
71 | } | 71 | } |
72 | 72 | ||
73 | fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { | 73 | fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { |
74 | let left = adj_comments(node, Direction::Backward); | 74 | let prev = adj_comments(node, Direction::Prev); |
75 | let right = adj_comments(node, Direction::Forward); | 75 | let next = adj_comments(node, Direction::Next); |
76 | if left != right { | 76 | if prev != next { |
77 | Some(TextRange::from_to( | 77 | Some(TextRange::from_to( |
78 | left.range().start(), | 78 | prev.range().start(), |
79 | right.range().end(), | 79 | next.range().end(), |
80 | )) | 80 | )) |
81 | } else { | 81 | } else { |
82 | None | 82 | None |
@@ -85,7 +85,7 @@ fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { | |||
85 | 85 | ||
86 | fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { | 86 | fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { |
87 | let mut res = node; | 87 | let mut res = node; |
88 | for node in siblings(node, dir) { | 88 | for node in node.siblings(dir) { |
89 | match node.kind() { | 89 | match node.kind() { |
90 | COMMENT => res = node, | 90 | COMMENT => res = node, |
91 | WHITESPACE if !node.leaf_text().unwrap().as_str().contains("\n\n") => (), | 91 | WHITESPACE if !node.leaf_text().unwrap().as_str().contains("\n\n") => (), |
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index 892aaf97b..733512368 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -3,7 +3,7 @@ use std::collections::HashSet; | |||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | File, TextRange, SyntaxNodeRef, | 4 | File, TextRange, SyntaxNodeRef, |
5 | SyntaxKind, | 5 | SyntaxKind, |
6 | algo::{Direction, siblings}, | 6 | Direction, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | #[derive(Debug, PartialEq, Eq)] | 9 | #[derive(Debug, PartialEq, Eq)] |
@@ -62,7 +62,7 @@ fn contiguous_range_for<'a>( | |||
62 | 62 | ||
63 | let left = node; | 63 | let left = node; |
64 | let mut right = node; | 64 | let mut right = node; |
65 | for node in siblings(node, Direction::Forward) { | 65 | for node in node.siblings(Direction::Next) { |
66 | visited.insert(node); | 66 | visited.insert(node); |
67 | match node.kind() { | 67 | match node.kind() { |
68 | SyntaxKind::WHITESPACE if !node.leaf_text().unwrap().as_str().contains("\n\n") => (), | 68 | SyntaxKind::WHITESPACE if !node.leaf_text().unwrap().as_str().contains("\n\n") => (), |