ink_analyzer_ir/tree/
ink_tree.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! ink! entity tree traversal types and abstractions.

use ra_ap_syntax::SyntaxNode;

use super::utils;
use crate::{InkArg, InkArgKind, InkAttribute};

/// A wrapper for ink! entity tree navigation methods that return opaque iterator types.
pub struct InkTree<'a> {
    /// The wrapped syntax node.
    syntax: &'a SyntaxNode,
}

impl<'a> InkTree<'a> {
    /// Creates an ink! entity tree instance for the syntax node.
    pub fn new(node: &'a SyntaxNode) -> Self {
        Self { syntax: node }
    }

    /// Returns ink! attributes for the ink! entity.
    pub fn ink_attrs(&self) -> impl Iterator<Item = InkAttribute> {
        utils::ink_attrs(self.syntax)
    }

    /// Returns ink! attributes for all the ink! entity's descendants.
    pub fn ink_attrs_descendants(&self) -> impl Iterator<Item = InkAttribute> {
        utils::ink_attrs_descendants(self.syntax)
    }

    /// Returns ink! attributes for all the ink! entity's descendants
    /// that don't have any ink! ancestors between them and the entity.
    pub fn ink_attrs_closest_descendants(&self) -> impl Iterator<Item = InkAttribute> {
        utils::ink_attrs_closest_descendants(self.syntax)
    }

    /// Returns ink! attributes in the ink! entity's scope.
    /// This includes both the ink! entity's own ink! attributes and those of all of it's descendants.
    pub fn ink_attrs_in_scope(&self) -> impl Iterator<Item = InkAttribute> {
        utils::ink_attrs_in_scope(self.syntax)
    }

    /// Returns ink! attributes for all the ink! entity's ancestors.
    pub fn ink_attrs_ancestors(&self) -> impl Iterator<Item = InkAttribute> + '_ {
        utils::ink_attrs_ancestors(self.syntax)
    }

    /// Returns ink! attributes for all the ink! entity's ancestors
    /// that don't have any ink! ancestors between them and the item.
    pub fn ink_attrs_closest_ancestors(&self) -> impl Iterator<Item = InkAttribute> {
        utils::ink_attrs_closest_ancestors(self.syntax)
    }

    /// Returns ink! arguments of the ink! entity.
    pub fn ink_args(&self) -> impl Iterator<Item = InkArg> {
        utils::ink_args(self.syntax)
    }

    /// Returns ink! arguments of a specific kind (if any) for the ink! entity.
    pub fn ink_args_by_kind(&self, kind: InkArgKind) -> impl Iterator<Item = InkArg> {
        utils::ink_args_by_kind(self.syntax, kind)
    }

    /// Returns ink! argument of a specific kind (if any) for the ink! entity.
    pub fn ink_arg_by_kind(&self, kind: InkArgKind) -> Option<InkArg> {
        utils::ink_arg_by_kind(self.syntax, kind)
    }
}