aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/algo.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
commit3f4be819125ce4a22edd86721fa56b5caba99c2e (patch)
treebe93895ddc08c911585d9f7bc64623a3741f32c6 /crates/ra_syntax/src/algo.rs
parent4e444d2bc24d16284401444fd2154f63e0f96070 (diff)
parent122410d7aa34a32d468a3173858cbc8a2bbc68f5 (diff)
Merge #449
449: switch to new rowan API r=matklad a=matklad closes https://github.com/rust-analyzer/rust-analyzer/issues/448 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/algo.rs')
-rw-r--r--crates/ra_syntax/src/algo.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs
index 4b3548ea9..13f50d2ef 100644
--- a/crates/ra_syntax/src/algo.rs
+++ b/crates/ra_syntax/src/algo.rs
@@ -1,19 +1,23 @@
1pub mod visit; 1pub mod visit;
2 2
3use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; 3use rowan::TransparentNewType;
4
5use crate::{SyntaxNode, TextRange, TextUnit};
4 6
5pub use rowan::LeafAtOffset; 7pub use rowan::LeafAtOffset;
6 8
7pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { 9pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<&SyntaxNode> {
8 match node.0.leaf_at_offset(offset) { 10 match node.0.leaf_at_offset(offset) {
9 LeafAtOffset::None => LeafAtOffset::None, 11 LeafAtOffset::None => LeafAtOffset::None,
10 LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode(n)), 12 LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode::from_repr(n)),
11 LeafAtOffset::Between(l, r) => LeafAtOffset::Between(SyntaxNode(l), SyntaxNode(r)), 13 LeafAtOffset::Between(l, r) => {
14 LeafAtOffset::Between(SyntaxNode::from_repr(l), SyntaxNode::from_repr(r))
15 }
12 } 16 }
13} 17}
14 18
15pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { 19pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode {
16 SyntaxNode(root.0.covering_node(range)) 20 SyntaxNode::from_repr(root.0.covering_node(range))
17} 21}
18 22
19pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { 23pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> {