return build_string (string);
}
+static TSTreeCursor treesit_cursor_helper (TSNode, Lisp_Object);
+
DEFUN ("treesit-node-parent",
Ftreesit_node_parent, Streesit_node_parent, 1, 1, 0,
doc: /* Return the immediate parent of NODE.
treesit_check_node (node);
treesit_initialize ();
- TSNode treesit_node = XTS_NODE (node)->node;
- TSNode parent = ts_node_parent (treesit_node);
-
- if (ts_node_is_null (parent))
- return Qnil;
+ Lisp_Object return_value = Qnil;
- return make_treesit_node (XTS_NODE (node)->parser, parent);
+ TSNode treesit_node = XTS_NODE (node)->node;
+ Lisp_Object parser = XTS_NODE (node)->parser;
+ TSTreeCursor cursor = treesit_cursor_helper (treesit_node, parser);
+ if (ts_tree_cursor_goto_parent (&cursor))
+ {
+ TSNode parent = ts_tree_cursor_current_node (&cursor);
+ return_value = make_treesit_node (parser, parent);
+ }
+ ts_tree_cursor_delete (&cursor);
+ return return_value;
}
DEFUN ("treesit-node-child",