mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Use text_range::extend_to
This commit is contained in:
parent
05388b4ea4
commit
61fd6c6270
4 changed files with 6 additions and 19 deletions
|
@ -388,7 +388,7 @@ fn original_range_and_origin(
|
||||||
let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
|
let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
|
||||||
== skip_trivia_token(node.value.last_token()?, Direction::Prev)?;
|
== 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 first = skip_trivia_token(it.first_token()?, Direction::Next)?;
|
||||||
let last = skip_trivia_token(it.last_token()?, Direction::Prev)?;
|
let last = skip_trivia_token(it.last_token()?, Direction::Prev)?;
|
||||||
|
|
||||||
|
@ -404,16 +404,9 @@ fn original_range_and_origin(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Add union method in TextRange
|
|
||||||
Some((
|
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,
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ fn extend_tokens_from_range(
|
||||||
.take_while(validate)
|
.take_while(validate)
|
||||||
.last()?;
|
.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 {
|
if original_range.is_subrange(&range) && original_range != range {
|
||||||
Some(range)
|
Some(range)
|
||||||
} else {
|
} 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.
|
/// Find the shallowest node with same range, which allows us to traverse siblings.
|
||||||
fn shallowest_node(node: &SyntaxNode) -> SyntaxNode {
|
fn shallowest_node(node: &SyntaxNode) -> SyntaxNode {
|
||||||
node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap()
|
node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap()
|
||||||
|
|
|
@ -9,7 +9,7 @@ publish = false
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
text_unit = "0.1.9"
|
text_unit = "0.1.10"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
|
|
@ -9,5 +9,5 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
difference = "2.0.0"
|
difference = "2.0.0"
|
||||||
text_unit = "0.1.9"
|
text_unit = "0.1.10"
|
||||||
serde_json = "1.0.48"
|
serde_json = "1.0.48"
|
||||||
|
|
Loading…
Reference in a new issue