aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-31 16:01:51 +0000
committerAleksey Kladov <[email protected]>2018-12-31 16:01:51 +0000
commitf1e8ebfbeb5f84405fb609e3841df02e270037c4 (patch)
tree6f444b4e85eab9f547b9b2c675c4f53fc169c464 /crates/ra_editor/src
parenta3ee07ac149867d1d7b9c00a752d0c46c337a878 (diff)
generalize extend selection to work with nodes
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/extend_selection.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index 4665a336a..bf0727dde 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -1,16 +1,11 @@
1use ra_syntax::{ 1use ra_syntax::{
2 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, 2 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset},
3 Direction, SourceFileNode, 3 Direction,
4 SyntaxKind::*, 4 SyntaxKind::*,
5 SyntaxNodeRef, TextRange, TextUnit, 5 SyntaxNodeRef, TextRange, TextUnit,
6}; 6};
7 7
8pub fn extend_selection(file: &SourceFileNode, range: TextRange) -> Option<TextRange> { 8pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> {
9 let syntax = file.syntax();
10 extend(syntax.borrowed(), range)
11}
12
13pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> {
14 if range.is_empty() { 9 if range.is_empty() {
15 let offset = range.start(); 10 let offset = range.start();
16 let mut leaves = find_leaf_at_offset(root, offset); 11 let mut leaves = find_leaf_at_offset(root, offset);
@@ -126,6 +121,7 @@ fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef {
126#[cfg(test)] 121#[cfg(test)]
127mod tests { 122mod tests {
128 use super::*; 123 use super::*;
124 use ra_syntax::SourceFileNode;
129 use test_utils::extract_offset; 125 use test_utils::extract_offset;
130 126
131 fn do_check(before: &str, afters: &[&str]) { 127 fn do_check(before: &str, afters: &[&str]) {
@@ -133,7 +129,7 @@ mod tests {
133 let file = SourceFileNode::parse(&before); 129 let file = SourceFileNode::parse(&before);
134 let mut range = TextRange::offset_len(cursor, 0.into()); 130 let mut range = TextRange::offset_len(cursor, 0.into());
135 for &after in afters { 131 for &after in afters {
136 range = extend_selection(&file, range).unwrap(); 132 range = extend_selection(file.syntax(), range).unwrap();
137 let actual = &before[range]; 133 let actual = &before[range];
138 assert_eq!(after, actual); 134 assert_eq!(after, actual);
139 } 135 }