diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 5b0b94e34d..c3d8ee1aef 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 2e09bd1ec3..f5a0633512 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 a321492997..97280f8669 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 971592b737..6a7c6d6f9e 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"