aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-02-27 02:06:48 +0000
committerEdwin Cheng <[email protected]>2020-02-27 02:06:48 +0000
commit61fd6c6270f9ebc37f4156ae1a4d41053a78cdb1 (patch)
tree714d8787e9f26bf2e57aaf6bd1aa14d70f6abde0
parent05388b4ea46c886fa4ec8a1d49b71eb816cf7c6d (diff)
Use text_range::extend_to
-rw-r--r--crates/ra_hir/src/semantics.rs13
-rw-r--r--crates/ra_ide/src/extend_selection.rs8
-rw-r--r--crates/ra_text_edit/Cargo.toml2
-rw-r--r--crates/test_utils/Cargo.toml2
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(
388 let single = skip_trivia_token(node.value.first_token()?, Direction::Next)? 388 let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
389 == skip_trivia_token(node.value.last_token()?, Direction::Prev)?; 389 == skip_trivia_token(node.value.last_token()?, Direction::Prev)?;
390 390
391 return Some(node.value.descendants().find_map(|it| { 391 Some(node.value.descendants().find_map(|it| {
392 let first = skip_trivia_token(it.first_token()?, Direction::Next)?; 392 let first = skip_trivia_token(it.first_token()?, Direction::Next)?;
393 let last = skip_trivia_token(it.last_token()?, Direction::Prev)?; 393 let last = skip_trivia_token(it.last_token()?, Direction::Prev)?;
394 394
@@ -404,16 +404,9 @@ fn original_range_and_origin(
404 return None; 404 return None;
405 } 405 }
406 406
407 // FIXME: Add union method in TextRange
408 Some(( 407 Some((
409 first.with_value(union_range(first.value.text_range(), last.value.text_range())), 408 first.with_value(first.value.text_range().extend_to(&last.value.text_range())),
410 first_origin, 409 first_origin,
411 )) 410 ))
412 })?); 411 })?)
413
414 fn union_range(a: TextRange, b: TextRange) -> TextRange {
415 let start = a.start().min(b.start());
416 let end = a.end().max(b.end());
417 TextRange::from_to(start, end)
418 }
419} 412}
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(
161 .take_while(validate) 161 .take_while(validate)
162 .last()?; 162 .last()?;
163 163
164 let range = union_range(first.text_range(), last.text_range()); 164 let range = first.text_range().extend_to(&last.text_range());
165 if original_range.is_subrange(&range) && original_range != range { 165 if original_range.is_subrange(&range) && original_range != range {
166 Some(range) 166 Some(range)
167 } else { 167 } else {
@@ -169,12 +169,6 @@ fn extend_tokens_from_range(
169 } 169 }
170} 170}
171 171
172fn union_range(range: TextRange, r: TextRange) -> TextRange {
173 let start = range.start().min(r.start());
174 let end = range.end().max(r.end());
175 TextRange::from_to(start, end)
176}
177
178/// Find the shallowest node with same range, which allows us to traverse siblings. 172/// Find the shallowest node with same range, which allows us to traverse siblings.
179fn shallowest_node(node: &SyntaxNode) -> SyntaxNode { 173fn shallowest_node(node: &SyntaxNode) -> SyntaxNode {
180 node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap() 174 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
9doctest = false 9doctest = false
10 10
11[dependencies] 11[dependencies]
12text_unit = "0.1.9" 12text_unit = "0.1.10"
13 13
14[dev-dependencies] 14[dev-dependencies]
15test_utils = { path = "../test_utils" } 15test_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
9 9
10[dependencies] 10[dependencies]
11difference = "2.0.0" 11difference = "2.0.0"
12text_unit = "0.1.9" 12text_unit = "0.1.10"
13serde_json = "1.0.48" 13serde_json = "1.0.48"