aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/extend_selection.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index 4757d8e22..1e7d0621a 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -145,25 +145,25 @@ fn extend_tokens_from_range(
145 let src = db.parse_or_expand(expanded.file_id)?; 145 let src = db.parse_or_expand(expanded.file_id)?;
146 let parent = shallowest_node(&find_covering_element(&src, expanded.value))?.parent()?; 146 let parent = shallowest_node(&find_covering_element(&src, expanded.value))?.parent()?;
147 147
148 let validate = |token: SyntaxToken| { 148 let validate = |token: &SyntaxToken| {
149 let node = descend_into_macros(db, file_id, token.clone()); 149 let node = descend_into_macros(db, file_id, token.clone());
150 if node.file_id == expanded.file_id 150 node.file_id == expanded.file_id
151 && node.value.text_range().is_subrange(&parent.text_range()) 151 && node.value.text_range().is_subrange(&parent.text_range())
152 {
153 Some(token)
154 } else {
155 None
156 }
157 }; 152 };
158 153
159 // Find the first and last text range under expanded parent 154 // Find the first and last text range under expanded parent
160 let first = successors(Some(first_token), |token| { 155 let first = successors(Some(first_token), |token| {
161 validate(skip_whitespace(token.prev_token()?, Direction::Prev)?) 156 let token = token.prev_token()?;
157 skip_whitespace(token, Direction::Prev)
162 }) 158 })
159 .take_while(validate)
163 .last()?; 160 .last()?;
161
164 let last = successors(Some(last_token), |token| { 162 let last = successors(Some(last_token), |token| {
165 validate(skip_whitespace(token.next_token()?, Direction::Next)?) 163 let token = token.next_token()?;
164 skip_whitespace(token, Direction::Next)
166 }) 165 })
166 .take_while(validate)
167 .last()?; 167 .last()?;
168 168
169 let range = union_range(first.text_range(), last.text_range()); 169 let range = union_range(first.text_range(), last.text_range());
@@ -334,10 +334,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment {
334 334
335#[cfg(test)] 335#[cfg(test)]
336mod tests { 336mod tests {
337 use super::*;
338 use crate::mock_analysis::single_file;
339 use test_utils::extract_offset; 337 use test_utils::extract_offset;
340 338
339 use crate::mock_analysis::single_file;
340
341 use super::*;
342
341 fn do_check(before: &str, afters: &[&str]) { 343 fn do_check(before: &str, afters: &[&str]) {
342 let (cursor, before) = extract_offset(before); 344 let (cursor, before) = extract_offset(before);
343 let (analysis, file_id) = single_file(&before); 345 let (analysis, file_id) = single_file(&before);