diff options
author | Aleksey Kladov <[email protected]> | 2019-01-08 17:44:31 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 18:01:41 +0000 |
commit | 702bdacb03b498f36ed9ccf4f37ca923affb1e9c (patch) | |
tree | 36be9bf0d15ef94cde0821ebe441e5540520b59c /crates/ra_syntax/src | |
parent | 1b82084a5f28506134c668a67d2759ef22be6a80 (diff) |
move node at offset to aglo already
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 13f50d2ef..2826ec7f2 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -2,7 +2,7 @@ pub mod visit; | |||
2 | 2 | ||
3 | use rowan::TransparentNewType; | 3 | use rowan::TransparentNewType; |
4 | 4 | ||
5 | use crate::{SyntaxNode, TextRange, TextUnit}; | 5 | use crate::{SyntaxNode, TextRange, TextUnit, AstNode}; |
6 | 6 | ||
7 | pub use rowan::LeafAtOffset; | 7 | pub use rowan::LeafAtOffset; |
8 | 8 | ||
@@ -16,6 +16,10 @@ pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset< | |||
16 | } | 16 | } |
17 | } | 17 | } |
18 | 18 | ||
19 | pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> { | ||
20 | find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) | ||
21 | } | ||
22 | |||
19 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { | 23 | pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode { |
20 | SyntaxNode::from_repr(root.0.covering_node(range)) | 24 | SyntaxNode::from_repr(root.0.covering_node(range)) |
21 | } | 25 | } |