aboutsummaryrefslogtreecommitdiff
path: root/lib/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/utils.rs')
-rw-r--r--lib/src/utils.rs16
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 @@
1use rnix::{SyntaxKind, SyntaxNode, TextRange};
2
3pub 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}