Use cursor API in treesit-node-parent
This is the last part of the change that fixes bug#60054. The previous change fixes it for searching functions, this fixes for treesit-node-parent. * src/treesit.c (Ftreesit_node_parent): Use the new cursor API.
This commit is contained in:
parent
5f0286c0af
commit
1fc7535546
1 changed files with 13 additions and 6 deletions
|
@ -1758,6 +1758,8 @@ If NODE is nil, return nil. */)
|
||||||
return build_string (string);
|
return build_string (string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TSTreeCursor treesit_cursor_helper (TSNode, Lisp_Object);
|
||||||
|
|
||||||
DEFUN ("treesit-node-parent",
|
DEFUN ("treesit-node-parent",
|
||||||
Ftreesit_node_parent, Streesit_node_parent, 1, 1, 0,
|
Ftreesit_node_parent, Streesit_node_parent, 1, 1, 0,
|
||||||
doc: /* Return the immediate parent of NODE.
|
doc: /* Return the immediate parent of NODE.
|
||||||
|
@ -1768,13 +1770,18 @@ Return nil if NODE has no parent. If NODE is nil, return nil. */)
|
||||||
treesit_check_node (node);
|
treesit_check_node (node);
|
||||||
treesit_initialize ();
|
treesit_initialize ();
|
||||||
|
|
||||||
|
Lisp_Object return_value = Qnil;
|
||||||
|
|
||||||
TSNode treesit_node = XTS_NODE (node)->node;
|
TSNode treesit_node = XTS_NODE (node)->node;
|
||||||
TSNode parent = ts_node_parent (treesit_node);
|
Lisp_Object parser = XTS_NODE (node)->parser;
|
||||||
|
TSTreeCursor cursor = treesit_cursor_helper (treesit_node, parser);
|
||||||
if (ts_node_is_null (parent))
|
if (ts_tree_cursor_goto_parent (&cursor))
|
||||||
return Qnil;
|
{
|
||||||
|
TSNode parent = ts_tree_cursor_current_node (&cursor);
|
||||||
return make_treesit_node (XTS_NODE (node)->parser, parent);
|
return_value = make_treesit_node (parser, parent);
|
||||||
|
}
|
||||||
|
ts_tree_cursor_delete (&cursor);
|
||||||
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFUN ("treesit-node-child",
|
DEFUN ("treesit-node-child",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue