diff options
author | Aleksey Kladov <[email protected]> | 2020-02-26 16:58:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-26 16:58:32 +0000 |
commit | 913cdcee8f0fe4373627d10d756949b970bcf5c2 (patch) | |
tree | 7f0e57819a98bb908d4511d1c57ea484520373e3 /crates/ra_syntax/src | |
parent | 6ea633c4940d25acea04e4945a8f905e65153c30 (diff) | |
parent | 553254973e24a2c0bdf1475fccbbc4603e8421f0 (diff) |
Merge pull request #3325 from edwin0cheng/skip-trival-token
Skip trival token in original_range
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index f14bcbb35..ebf59288a 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -7,7 +7,8 @@ use ra_text_edit::TextEditBuilder; | |||
7 | use rustc_hash::{FxHashMap, FxHashSet}; | 7 | use rustc_hash::{FxHashMap, FxHashSet}; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, | 10 | AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, |
11 | TextRange, TextUnit, | ||
11 | }; | 12 | }; |
12 | 13 | ||
13 | /// Returns ancestors of the node at the offset, sorted by length. This should | 14 | /// Returns ancestors of the node at the offset, sorted by length. This should |
@@ -37,6 +38,17 @@ pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> | |||
37 | ancestors_at_offset(syntax, offset).find_map(N::cast) | 38 | ancestors_at_offset(syntax, offset).find_map(N::cast) |
38 | } | 39 | } |
39 | 40 | ||
41 | /// Skip to next non `trivia` token | ||
42 | pub fn skip_trivia_token(mut token: SyntaxToken, direction: Direction) -> Option<SyntaxToken> { | ||
43 | while token.kind().is_trivia() { | ||
44 | token = match direction { | ||
45 | Direction::Next => token.next_token()?, | ||
46 | Direction::Prev => token.prev_token()?, | ||
47 | } | ||
48 | } | ||
49 | Some(token) | ||
50 | } | ||
51 | |||
40 | /// Finds the first sibling in the given direction which is not `trivia` | 52 | /// Finds the first sibling in the given direction which is not `trivia` |
41 | pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Option<SyntaxElement> { | 53 | pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Option<SyntaxElement> { |
42 | return match element { | 54 | return match element { |