From d7da42bd402aedb167bfb33aec7ce61279716ff7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 25 Feb 2020 14:59:13 +0100 Subject: Simplify --- crates/ra_ide/src/extend_selection.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'crates/ra_ide') 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( let src = db.parse_or_expand(expanded.file_id)?; let parent = shallowest_node(&find_covering_element(&src, expanded.value))?.parent()?; - let validate = |token: SyntaxToken| { + let validate = |token: &SyntaxToken| { let node = descend_into_macros(db, file_id, token.clone()); - if node.file_id == expanded.file_id + node.file_id == expanded.file_id && node.value.text_range().is_subrange(&parent.text_range()) - { - Some(token) - } else { - None - } }; // Find the first and last text range under expanded parent let first = successors(Some(first_token), |token| { - validate(skip_whitespace(token.prev_token()?, Direction::Prev)?) + let token = token.prev_token()?; + skip_whitespace(token, Direction::Prev) }) + .take_while(validate) .last()?; + let last = successors(Some(last_token), |token| { - validate(skip_whitespace(token.next_token()?, Direction::Next)?) + let token = token.next_token()?; + skip_whitespace(token, Direction::Next) }) + .take_while(validate) .last()?; let range = union_range(first.text_range(), last.text_range()); @@ -334,10 +334,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment { #[cfg(test)] mod tests { - use super::*; - use crate::mock_analysis::single_file; use test_utils::extract_offset; + use crate::mock_analysis::single_file; + + use super::*; + fn do_check(before: &str, afters: &[&str]) { let (cursor, before) = extract_offset(before); let (analysis, file_id) = single_file(&before); -- cgit v1.2.3