From 665f5a0793bcf86a9620a747683666ed16b6b5d9 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 14 Feb 2024 15:44:47 -0500 Subject: [PATCH] docs: explicitly mention behavior of walking outside the given "root" node for a `TSTreeCursor` --- docs/section-2-using-parsers.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/section-2-using-parsers.md b/docs/section-2-using-parsers.md index a886f6ff..7929b8f3 100644 --- a/docs/section-2-using-parsers.md +++ b/docs/section-2-using-parsers.md @@ -410,6 +410,12 @@ Internally, copying a syntax tree just entails incrementing an atomic reference You can access every node in a syntax tree using the `TSNode` APIs [described above](#retrieving-nodes), but if you need to access a large number of nodes, the fastest way to do so is with a _tree cursor_. A cursor is a stateful object that allows you to walk a syntax tree with maximum efficiency. +Note that the given input node is considered the root of the cursor, and the +cursor cannot walk outside this node, so going to the parent or any sibling +of the root node will return `false`. This has no unexpected effects if the given +input node is the actual `root` node of the tree, but is something to keep in mind +when using nodes that are not the `root` node. + You can initialize a cursor from any node: ```c