aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/extend_selection.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-02 16:14:33 +0100
committerAleksey Kladov <[email protected]>2018-10-02 16:14:33 +0100
commit1a2a8dec14ec04ea8eeccae99fd885e7a280e45b (patch)
treef94bb3a8bd47e3612ef29e815532c07d7871fa0f /crates/ra_editor/src/extend_selection.rs
parentd323c81d5cc6a198239285abcede2166181d8f39 (diff)
Make siblings an inherent method
Diffstat (limited to 'crates/ra_editor/src/extend_selection.rs')
-rw-r--r--crates/ra_editor/src/extend_selection.rs16
1 files changed, 8 insertions, 8 deletions
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 @@
1use ra_syntax::{ 1use 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
7pub fn extend_selection(file: &File, range: TextRange) -> Option<TextRange> { 7pub 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
73fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { 73fn 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
86fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { 86fn 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") => (),