From 553254973e24a2c0bdf1475fccbbc4603e8421f0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 27 Feb 2020 00:12:26 +0800 Subject: Skip trival token in original_range --- crates/ra_syntax/src/algo.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') 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; use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ - AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, + AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, + TextRange, TextUnit, }; /// Returns ancestors of the node at the offset, sorted by length. This should @@ -37,6 +38,17 @@ pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextUnit) -> ancestors_at_offset(syntax, offset).find_map(N::cast) } +/// Skip to next non `trivia` token +pub fn skip_trivia_token(mut token: SyntaxToken, direction: Direction) -> Option { + while token.kind().is_trivia() { + token = match direction { + Direction::Next => token.next_token()?, + Direction::Prev => token.prev_token()?, + } + } + Some(token) +} + /// Finds the first sibling in the given direction which is not `trivia` pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Option { return match element { -- cgit v1.2.3