]> git.eshelyaron.com Git - emacs.git/commit
Switch to use cursor API in treesit.c
authorYuan Fu <casouri@gmail.com>
Sat, 17 Dec 2022 23:01:57 +0000 (15:01 -0800)
committerYuan Fu <casouri@gmail.com>
Sat, 17 Dec 2022 23:33:54 +0000 (15:33 -0800)
commit5f0286c0afa9811e8042911b738a452c1e632c9d
tree773e7696491ff684ad994910f1da72557ec914e4
parenta275e436df438806a5a4f8c57423085a7147eb0a
Switch to use cursor API in treesit.c

ts_node_parent has bugs (bug#60054), using cursor API avoids that.
Tree-sitter's author might remove ts_node_parent in the future, so
might as well switch to use cursors now.  We are basically
reimplementing some of the logic of ts_node_prev_sibling and
ts_node_parent in the sibling helper and cursor helper functions.

See also https://github.com/tree-sitter/tree-sitter/issues/1992

* src/treesit.c (treesit_traverse_sibling_helper)
(treesit_traverse_child_helper)
(treesit_traverse_match_predicate): Reimplemented to use the cursor API.
(treesit_search_dfs)
(treesit_search_forward): Use the new cursor helper functions.
(Ftreesit_search_subtree)
(Ftreesit_search_forward)
(Ftreesit_induce_sparse_tree): Use cursors.

* test/src/treesit-tests.el (treesit-search-subtree): New test.
(treesit--ert-search-setup): New macro.
(treesit-search-forward)
(treesit-search-forward-named-only)
(treesit-search-backward)
(treesit-search-backward-named-only)
(treesit-cursor-helper-with-missing-node): New tests.
src/treesit.c
test/src/treesit-tests.el