diff options
author | Denis Zubarev <dvzubarev@yandex.ru> | 2023-11-12 01:42:42 +0300 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-12-18 18:25:26 -0800 |
commit | 7b315e8a5c966f8d11a4f646db4e29b989b56ab1 (patch) | |
tree | 46c8b7361d03583a3865165dde5e03c55cc877e8 | |
parent | 03625c2fefa682f74775abc1e223e17557d58bc7 (diff) | |
download | emacs-7b315e8a5c966f8d11a4f646db4e29b989b56ab1.tar.gz emacs-7b315e8a5c966f8d11a4f646db4e29b989b56ab1.tar.bz2 emacs-7b315e8a5c966f8d11a4f646db4e29b989b56ab1.zip |
Fix an issue when searching subtree backward (bug#67117)
* src/treesit.c (treesit_traverse_child_helper):
Do not call treesit_traverse_sibling_helper when the named node is
required and the last child is the named node.
Otherwise treesit_traverse_sibling_helper will move cursor to the
previous sibling and last node will be skipped.
* test/src/treesit-tests.el (treesit-search-subtree-forward-1):
(treesit-search-subtree-backward-1):
Add tests.
-rw-r--r-- | src/treesit.c | 4 | ||||
-rw-r--r-- | test/src/treesit-tests.el | 30 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/treesit.c b/src/treesit.c index 45de82ec096..04ea8958b96 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -3061,9 +3061,9 @@ treesit_traverse_child_helper (TSTreeCursor *cursor, /* First go to the last child. */ while (ts_tree_cursor_goto_next_sibling (cursor)); - if (!named) + if (!named || (named && ts_node_is_named (ts_tree_cursor_current_node(cursor)))) return true; - /* Else named... */ + /* Else named is required and last child is not named node */ if (treesit_traverse_sibling_helper(cursor, false, true)) return true; else diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index 69db37fc0b4..9ba3a9340c1 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el @@ -1083,6 +1083,36 @@ This tests bug#60355." treesit--ert-defun-navigation-python-program treesit--ert-defun-navigation-top-level-master))) +(ert-deftest treesit-search-subtree-forward-1 () + "Test search subtree forward." + (skip-unless (treesit-language-available-p 'python)) + (require 'python) + (python-ts-mode) + (insert "Temp(1, 2)") + (goto-char (point-min)) + (let ((node (treesit-search-subtree + (treesit--thing-at (point) "call") + (lambda (n) (equal (treesit-node-type n ) "integer"))))) + + (should node) + (should (equal (treesit-node-text node) "1")))) + +(ert-deftest treesit-search-subtree-backward-1 () + "Test search subtree with backward=t." + (skip-unless (treesit-language-available-p 'python)) + (require 'python) + (python-ts-mode) + (insert "Temp(1, 2)") + (goto-char (point-min)) + (let ((node (treesit-search-subtree + (treesit--thing-at (point) "call") + (lambda (n) (equal (treesit-node-type n ) "integer")) + t))) + + (should node) + (should (equal (treesit-node-text node) "2")))) + + ;; TODO ;; - Functions in treesit.el ;; - treesit-load-name-override-list |