aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/extend_selection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/extend_selection.rs')
-rw-r--r--crates/ra_ide/src/extend_selection.rs24
1 files changed, 7 insertions, 17 deletions
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index 86e6f12d7..2e09bd1ec 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -5,7 +5,7 @@ use std::iter::successors;
5use hir::Semantics; 5use hir::Semantics;
6use ra_ide_db::RootDatabase; 6use ra_ide_db::RootDatabase;
7use ra_syntax::{ 7use ra_syntax::{
8 algo::{self, find_covering_element}, 8 algo::{self, find_covering_element, skip_trivia_token},
9 ast::{self, AstNode, AstToken}, 9 ast::{self, AstNode, AstToken},
10 Direction, NodeOrToken, 10 Direction, NodeOrToken,
11 SyntaxKind::{self, *}, 11 SyntaxKind::{self, *},
@@ -118,14 +118,14 @@ fn extend_tokens_from_range(
118 NodeOrToken::Token(it) => (it.clone(), it), 118 NodeOrToken::Token(it) => (it.clone(), it),
119 }; 119 };
120 120
121 let mut first_token = skip_whitespace(first_token, Direction::Next)?; 121 let mut first_token = skip_trivia_token(first_token, Direction::Next)?;
122 let mut last_token = skip_whitespace(last_token, Direction::Prev)?; 122 let mut last_token = skip_trivia_token(last_token, Direction::Prev)?;
123 123
124 while !first_token.text_range().is_subrange(&original_range) { 124 while !first_token.text_range().is_subrange(&original_range) {
125 first_token = skip_whitespace(first_token.next_token()?, Direction::Next)?; 125 first_token = skip_trivia_token(first_token.next_token()?, Direction::Next)?;
126 } 126 }
127 while !last_token.text_range().is_subrange(&original_range) { 127 while !last_token.text_range().is_subrange(&original_range) {
128 last_token = skip_whitespace(last_token.prev_token()?, Direction::Prev)?; 128 last_token = skip_trivia_token(last_token.prev_token()?, Direction::Prev)?;
129 } 129 }
130 130
131 // compute original mapped token range 131 // compute original mapped token range
@@ -149,14 +149,14 @@ fn extend_tokens_from_range(
149 // Find the first and last text range under expanded parent 149 // Find the first and last text range under expanded parent
150 let first = successors(Some(first_token), |token| { 150 let first = successors(Some(first_token), |token| {
151 let token = token.prev_token()?; 151 let token = token.prev_token()?;
152 skip_whitespace(token, Direction::Prev) 152 skip_trivia_token(token, Direction::Prev)
153 }) 153 })
154 .take_while(validate) 154 .take_while(validate)
155 .last()?; 155 .last()?;
156 156
157 let last = successors(Some(last_token), |token| { 157 let last = successors(Some(last_token), |token| {
158 let token = token.next_token()?; 158 let token = token.next_token()?;
159 skip_whitespace(token, Direction::Next) 159 skip_trivia_token(token, Direction::Next)
160 }) 160 })
161 .take_while(validate) 161 .take_while(validate)
162 .last()?; 162 .last()?;
@@ -169,16 +169,6 @@ fn extend_tokens_from_range(
169 } 169 }
170} 170}
171 171
172fn skip_whitespace(mut token: SyntaxToken, direction: Direction) -> Option<SyntaxToken> {
173 while token.kind() == WHITESPACE {
174 token = match direction {
175 Direction::Next => token.next_token()?,
176 Direction::Prev => token.prev_token()?,
177 }
178 }
179 Some(token)
180}
181
182fn union_range(range: TextRange, r: TextRange) -> TextRange { 172fn union_range(range: TextRange, r: TextRange) -> TextRange {
183 let start = range.start().min(r.start()); 173 let start = range.start().min(r.start());
184 let end = range.end().max(r.end()); 174 let end = range.end().max(r.end());