diff options
author | Aleksey Kladov <[email protected]> | 2019-01-08 17:47:37 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 18:01:41 +0000 |
commit | 0c88360eb46c44935421c5d4bc36910ce3e96782 (patch) | |
tree | d997e64093f919bee3cbaae766b3e1fa2e44096e | |
parent | 13301f284c63440d3354f74b51cb5a504d1e6eef (diff) |
add comment
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 2826ec7f2..45747e21d 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -16,6 +16,15 @@ pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset< | |||
16 | } | 16 | } |
17 | } | 17 | } |
18 | 18 | ||
19 | /// Finds a node of specific Ast type at offset. Note that this is slightly | ||
20 | /// impercise: if the cursor is strictly betwen two nodes of the desired type, | ||
21 | /// as in | ||
22 | /// | ||
23 | /// ```no-run | ||
24 | /// struct Foo {}|struct Bar; | ||
25 | /// ``` | ||
26 | /// | ||
27 | /// then the left node will be silently prefered. | ||
19 | pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> { | 28 | 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)) | 29 | find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) |
21 | } | 30 | } |