diff options
author | Aleksey Kladov <[email protected]> | 2019-01-07 13:15:47 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 08:20:15 +0000 |
commit | d91a98ec843ec8562c58ccb01a1e29d00cc744dc (patch) | |
tree | c628b6afbbe2e3a31ea88e6c16f556309dd0dde9 /crates/ra_syntax/src/algo.rs | |
parent | 55272f2023e69f3eff727ecbf77078e1b45e7f86 (diff) |
switch ra_syntax to new rowan API
Diffstat (limited to 'crates/ra_syntax/src/algo.rs')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 16 |
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 @@ | |||
1 | pub mod visit; | 1 | pub mod visit; |
2 | 2 | ||
3 | use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; | 3 | use rowan::TransparentNewType; |
4 | |||
5 | use crate::{SyntaxNode, TextRange, TextUnit}; | ||
4 | 6 | ||
5 | pub use rowan::LeafAtOffset; | 7 | pub use rowan::LeafAtOffset; |
6 | 8 | ||
7 | pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { | 9 | pub 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 | ||
15 | pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { | 19 | pub 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 | ||
19 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { | 23 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { |