diff options
Diffstat (limited to 'lib/src/utils.rs')
-rw-r--r-- | lib/src/utils.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/src/utils.rs b/lib/src/utils.rs new file mode 100644 index 0000000..d7cf4c8 --- /dev/null +++ b/lib/src/utils.rs | |||
@@ -0,0 +1,16 @@ | |||
1 | use rnix::{SyntaxKind, SyntaxNode, TextRange}; | ||
2 | |||
3 | pub fn with_preceeding_whitespace(node: &SyntaxNode) -> TextRange { | ||
4 | let start = node | ||
5 | .prev_sibling_or_token() | ||
6 | .map(|t| { | ||
7 | if t.kind() == SyntaxKind::TOKEN_WHITESPACE { | ||
8 | t.text_range().start() | ||
9 | } else { | ||
10 | t.text_range().end() | ||
11 | } | ||
12 | }) | ||
13 | .unwrap_or(node.text_range().start()); | ||
14 | let end = node.text_range().end(); | ||
15 | TextRange::new(start, end) | ||
16 | } | ||