From 61fd6c6270f9ebc37f4156ae1a4d41053a78cdb1 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 27 Feb 2020 10:06:48 +0800 Subject: Use text_range::extend_to --- crates/ra_hir/src/semantics.rs | 13 +++---------- crates/ra_ide/src/extend_selection.rs | 8 +------- crates/ra_text_edit/Cargo.toml | 2 +- crates/test_utils/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 5b0b94e34..c3d8ee1ae 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -388,7 +388,7 @@ fn original_range_and_origin( let single = skip_trivia_token(node.value.first_token()?, Direction::Next)? == skip_trivia_token(node.value.last_token()?, Direction::Prev)?; - return Some(node.value.descendants().find_map(|it| { + Some(node.value.descendants().find_map(|it| { let first = skip_trivia_token(it.first_token()?, Direction::Next)?; let last = skip_trivia_token(it.last_token()?, Direction::Prev)?; @@ -404,16 +404,9 @@ fn original_range_and_origin( return None; } - // FIXME: Add union method in TextRange Some(( - first.with_value(union_range(first.value.text_range(), last.value.text_range())), + first.with_value(first.value.text_range().extend_to(&last.value.text_range())), first_origin, )) - })?); - - fn union_range(a: TextRange, b: TextRange) -> TextRange { - let start = a.start().min(b.start()); - let end = a.end().max(b.end()); - TextRange::from_to(start, end) - } + })?) } diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 2e09bd1ec..f5a063351 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -161,7 +161,7 @@ fn extend_tokens_from_range( .take_while(validate) .last()?; - let range = union_range(first.text_range(), last.text_range()); + let range = first.text_range().extend_to(&last.text_range()); if original_range.is_subrange(&range) && original_range != range { Some(range) } else { @@ -169,12 +169,6 @@ fn extend_tokens_from_range( } } -fn union_range(range: TextRange, r: TextRange) -> TextRange { - let start = range.start().min(r.start()); - let end = range.end().max(r.end()); - TextRange::from_to(start, end) -} - /// Find the shallowest node with same range, which allows us to traverse siblings. fn shallowest_node(node: &SyntaxNode) -> SyntaxNode { node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap() diff --git a/crates/ra_text_edit/Cargo.toml b/crates/ra_text_edit/Cargo.toml index a32149299..97280f866 100644 --- a/crates/ra_text_edit/Cargo.toml +++ b/crates/ra_text_edit/Cargo.toml @@ -9,7 +9,7 @@ publish = false doctest = false [dependencies] -text_unit = "0.1.9" +text_unit = "0.1.10" [dev-dependencies] test_utils = { path = "../test_utils" } diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 971592b73..6a7c6d6f9 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml @@ -9,5 +9,5 @@ doctest = false [dependencies] difference = "2.0.0" -text_unit = "0.1.9" +text_unit = "0.1.10" serde_json = "1.0.48" -- cgit v1.2.3