aboutsummaryrefslogtreecommitdiff
path: root/lib/src/utils.rs
blob: d7cf4c8116f94a23a258bf7524de0a419d71e297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use rnix::{SyntaxKind, SyntaxNode, TextRange};

pub fn with_preceeding_whitespace(node: &SyntaxNode) -> TextRange {
    let start = node
        .prev_sibling_or_token()
        .map(|t| {
            if t.kind() == SyntaxKind::TOKEN_WHITESPACE {
                t.text_range().start()
            } else {
                t.text_range().end()
            }
        })
        .unwrap_or(node.text_range().start());
    let end = node.text_range().end();
    TextRange::new(start, end)
}