aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/syntax/src/ptr.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs
index 32aa69979..282470bae 100644
--- a/crates/syntax/src/ptr.rs
+++ b/crates/syntax/src/ptr.rs
@@ -32,6 +32,15 @@ impl SyntaxNodePtr {
32 SyntaxNodePtr { range: node.text_range(), kind: node.kind() } 32 SyntaxNodePtr { range: node.text_range(), kind: node.kind() }
33 } 33 }
34 34
35 /// "Dereference" the pointer to get the node it points to.
36 ///
37 /// Panics if node is not found, so make sure that `root` syntax tree is
38 /// equivalent (is build from the same text) to the tree which was
39 /// originally used to get this [`SyntaxNodePtr`].
40 ///
41 /// The complexity is linear in the depth of the tree and logarithmic in
42 /// tree width. As most trees are shallow, thinking about this as
43 /// `O(log(N))` in the size of the tree is not too wrong!
35 pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { 44 pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode {
36 assert!(root.parent().is_none()); 45 assert!(root.parent().is_none());
37 successors(Some(root.clone()), |node| { 46 successors(Some(root.clone()), |node| {