diff options
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r-- | crates/ra_editor/src/extend_selection.rs | 12 | ||||
-rw-r--r-- | crates/ra_editor/src/lib.rs | 6 |
2 files changed, 7 insertions, 11 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 @@ | |||
1 | use ra_syntax::{ | 1 | use 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 | ||
8 | pub fn extend_selection(file: &SourceFileNode, range: TextRange) -> Option<TextRange> { | 8 | pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> { |
9 | let syntax = file.syntax(); | ||
10 | extend(syntax.borrowed(), range) | ||
11 | } | ||
12 | |||
13 | pub(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)] |
127 | mod tests { | 122 | mod 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 | } |
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index 412b8aea9..b03f9ea54 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -67,11 +67,11 @@ pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUni | |||
67 | Some(matching_node.range().start()) | 67 | Some(matching_node.range().start()) |
68 | } | 68 | } |
69 | 69 | ||
70 | pub fn highlight(file: &SourceFileNode) -> Vec<HighlightedRange> { | 70 | pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> { |
71 | // Visited nodes to handle highlighting priorities | 71 | // Visited nodes to handle highlighting priorities |
72 | let mut highlighted = FxHashSet::default(); | 72 | let mut highlighted = FxHashSet::default(); |
73 | let mut res = Vec::new(); | 73 | let mut res = Vec::new(); |
74 | for node in file.syntax().descendants() { | 74 | for node in root.descendants() { |
75 | if highlighted.contains(&node) { | 75 | if highlighted.contains(&node) { |
76 | continue; | 76 | continue; |
77 | } | 77 | } |
@@ -143,7 +143,7 @@ fn main() {} | |||
143 | println!("Hello, {}!", 92); | 143 | println!("Hello, {}!", 92); |
144 | "#, | 144 | "#, |
145 | ); | 145 | ); |
146 | let hls = highlight(&file); | 146 | let hls = highlight(file.syntax()); |
147 | assert_eq_dbg( | 147 | assert_eq_dbg( |
148 | r#"[HighlightedRange { range: [1; 11), tag: "comment" }, | 148 | r#"[HighlightedRange { range: [1; 11), tag: "comment" }, |
149 | HighlightedRange { range: [12; 14), tag: "keyword" }, | 149 | HighlightedRange { range: [12; 14), tag: "keyword" }, |