* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
@ 2023-11-11 23:38 Denis Zubarev
2023-11-15 13:21 ` Eli Zaretskii
0 siblings, 1 reply; 20+ messages in thread
From: Denis Zubarev @ 2023-11-11 23:38 UTC (permalink / raw)
To: 67117
[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]
Tags: patch
Steps to reproduce the issue:
1. emacs -Q
2. M-x find-file /tmp/t.py
3. paste to the buffer
Temp(1, 2)
4. M-x python-ts-mode
5. Call search-subtree with backward flag
M-x eval-expression (treesit-search-subtree
(treesit--thing-at (point) "call")
(lambda (n) (equal (treesit-node-type n ) "integer"))
t)
It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
I fixed it in 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 the last node will be skipped.
I've added test for this bug.
In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo version 1.16.0) of 2023-11-12 built on NUC-here
Repository revision: 400a71b8f2c5a49dce4f542adfd2fdb59eb34243
Repository branch: search-subtree-bacward-fix
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Ubuntu 22.04.3 LTS
Configured using:
'configure --with-modules --with-native-compilation=aot
--with-imagemagick --with-json --with-tree-sitter --with-xft'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-an-issue-when-searching-subtree-backward.patch --]
[-- Type: text/patch, Size: 2721 bytes --]
From 88e913940cdd3c82afbdf2ad6520e1a1b9c2797b Mon Sep 17 00:00:00 2001
From: Denis Zubarev <dvzubarev@yandex.ru>
Date: Sun, 12 Nov 2023 01:42:42 +0300
Subject: [PATCH] Fix an issue when searching subtree backward
* 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
---
src/treesit.c | 4 ++--
test/src/treesit-tests.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/treesit.c b/src/treesit.c
index 69b59fca11..4dcad751f4 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3247,9 +3247,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 791e902bd0..c9b15c618c 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -1167,6 +1167,36 @@ treesit-defun-navigation-top-level
treesit--ert-defun-navigation-top-level-master
'top-level))
+(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
--
2.34.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-11 23:38 bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward Denis Zubarev
@ 2023-11-15 13:21 ` Eli Zaretskii
2023-11-15 17:01 ` Eli Zaretskii
2023-11-18 18:47 ` Yuan Fu
0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-15 13:21 UTC (permalink / raw)
To: Denis Zubarev, Yuan Fu; +Cc: 67117
> From: Denis Zubarev <dvzubarev@yandex.ru>
> Date: Sun, 12 Nov 2023 02:38:33 +0300
>
> Steps to reproduce the issue:
> 1. emacs -Q
> 2. M-x find-file /tmp/t.py
> 3. paste to the buffer
>
> Temp(1, 2)
>
> 4. M-x python-ts-mode
> 5. Call search-subtree with backward flag
> M-x eval-expression (treesit-search-subtree
> (treesit--thing-at (point) "call")
> (lambda (n) (equal (treesit-node-type n ) "integer"))
> t)
> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
Yuan, any comments to the patch and the issue in general?
Denis, your changes are too large for us to accept them without a
copyright assignment. Would you like to start your assignment
paperwork at this time, so that we could accept this contribution, and
all your future ones?
Thanks.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-15 13:21 ` Eli Zaretskii
@ 2023-11-15 17:01 ` Eli Zaretskii
2023-11-18 18:47 ` Yuan Fu
1 sibling, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-15 17:01 UTC (permalink / raw)
To: dvzubarev; +Cc: 67117, casouri
> Cc: 67117@debbugs.gnu.org
> Date: Wed, 15 Nov 2023 15:21:59 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> Denis, your changes are too large for us to accept them without a
> copyright assignment. Would you like to start your assignment
> paperwork at this time, so that we could accept this contribution, and
> all your future ones?
Oops, I see that you already started the paperwork. So let's wait for
it to run to completion.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-15 13:21 ` Eli Zaretskii
2023-11-15 17:01 ` Eli Zaretskii
@ 2023-11-18 18:47 ` Yuan Fu
2023-11-19 5:47 ` Eli Zaretskii
1 sibling, 1 reply; 20+ messages in thread
From: Yuan Fu @ 2023-11-18 18:47 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 67117, Denis Zubarev
> On Nov 15, 2023, at 5:21 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Denis Zubarev <dvzubarev@yandex.ru>
>> Date: Sun, 12 Nov 2023 02:38:33 +0300
>>
>> Steps to reproduce the issue:
>> 1. emacs -Q
>> 2. M-x find-file /tmp/t.py
>> 3. paste to the buffer
>>
>> Temp(1, 2)
>>
>> 4. M-x python-ts-mode
>> 5. Call search-subtree with backward flag
>> M-x eval-expression (treesit-search-subtree
>> (treesit--thing-at (point) "call")
>> (lambda (n) (equal (treesit-node-type n ) "integer"))
>> t)
>> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
>
> Yuan, any comments to the patch and the issue in general?
LGTM. Thanks Denis, and Eli :-)
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-18 18:47 ` Yuan Fu
@ 2023-11-19 5:47 ` Eli Zaretskii
2023-11-19 6:13 ` Yuan Fu
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-19 5:47 UTC (permalink / raw)
To: Yuan Fu; +Cc: 67117, dvzubarev
> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 18 Nov 2023 10:47:47 -0800
> Cc: Denis Zubarev <dvzubarev@yandex.ru>,
> 67117@debbugs.gnu.org
>
>
> >> Steps to reproduce the issue:
> >> 1. emacs -Q
> >> 2. M-x find-file /tmp/t.py
> >> 3. paste to the buffer
> >>
> >> Temp(1, 2)
> >>
> >> 4. M-x python-ts-mode
> >> 5. Call search-subtree with backward flag
> >> M-x eval-expression (treesit-search-subtree
> >> (treesit--thing-at (point) "call")
> >> (lambda (n) (equal (treesit-node-type n ) "integer"))
> >> t)
> >> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
> >
> > Yuan, any comments to the patch and the issue in general?
>
> LGTM. Thanks Denis, and Eli :-)
Should we install this on the emacs-29 branch or on master?
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 5:47 ` Eli Zaretskii
@ 2023-11-19 6:13 ` Yuan Fu
2023-11-19 6:40 ` Eli Zaretskii
2023-11-19 9:15 ` Eli Zaretskii
0 siblings, 2 replies; 20+ messages in thread
From: Yuan Fu @ 2023-11-19 6:13 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 67117, dvzubarev
> On Nov 18, 2023, at 9:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 18 Nov 2023 10:47:47 -0800
>> Cc: Denis Zubarev <dvzubarev@yandex.ru>,
>> 67117@debbugs.gnu.org
>>
>>
>>>> Steps to reproduce the issue:
>>>> 1. emacs -Q
>>>> 2. M-x find-file /tmp/t.py
>>>> 3. paste to the buffer
>>>>
>>>> Temp(1, 2)
>>>>
>>>> 4. M-x python-ts-mode
>>>> 5. Call search-subtree with backward flag
>>>> M-x eval-expression (treesit-search-subtree
>>>> (treesit--thing-at (point) "call")
>>>> (lambda (n) (equal (treesit-node-type n ) "integer"))
>>>> t)
>>>> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
>>>
>>> Yuan, any comments to the patch and the issue in general?
>>
>> LGTM. Thanks Denis, and Eli :-)
>
> Should we install this on the emacs-29 branch or on master?
Emacs-29, I’d say, since it’s a bug fix. Why do you ask?
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 6:13 ` Yuan Fu
@ 2023-11-19 6:40 ` Eli Zaretskii
2023-11-21 4:23 ` Yuan Fu
2023-11-19 9:15 ` Eli Zaretskii
1 sibling, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-19 6:40 UTC (permalink / raw)
To: Yuan Fu; +Cc: 67117, dvzubarev
> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 18 Nov 2023 22:13:49 -0800
> Cc: dvzubarev@yandex.ru,
> 67117@debbugs.gnu.org
>
>
>
> > On Nov 18, 2023, at 9:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> >> From: Yuan Fu <casouri@gmail.com>
> >> Date: Sat, 18 Nov 2023 10:47:47 -0800
> >> Cc: Denis Zubarev <dvzubarev@yandex.ru>,
> >> 67117@debbugs.gnu.org
> >>
> >>
> >>>> Steps to reproduce the issue:
> >>>> 1. emacs -Q
> >>>> 2. M-x find-file /tmp/t.py
> >>>> 3. paste to the buffer
> >>>>
> >>>> Temp(1, 2)
> >>>>
> >>>> 4. M-x python-ts-mode
> >>>> 5. Call search-subtree with backward flag
> >>>> M-x eval-expression (treesit-search-subtree
> >>>> (treesit--thing-at (point) "call")
> >>>> (lambda (n) (equal (treesit-node-type n ) "integer"))
> >>>> t)
> >>>> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
> >>>
> >>> Yuan, any comments to the patch and the issue in general?
> >>
> >> LGTM. Thanks Denis, and Eli :-)
> >
> > Should we install this on the emacs-29 branch or on master?
>
> Emacs-29, I’d say, since it’s a bug fix. Why do you ask?
Because I want to install it, obviously.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 6:13 ` Yuan Fu
2023-11-19 6:40 ` Eli Zaretskii
@ 2023-11-19 9:15 ` Eli Zaretskii
2023-11-19 11:25 ` Denis Zubarev
1 sibling, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-19 9:15 UTC (permalink / raw)
To: dvzubarev, Yuan Fu; +Cc: 67117
> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 18 Nov 2023 22:13:49 -0800
> Cc: dvzubarev@yandex.ru,
> 67117@debbugs.gnu.org
>
>
>
> > On Nov 18, 2023, at 9:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> >> From: Yuan Fu <casouri@gmail.com>
> >> Date: Sat, 18 Nov 2023 10:47:47 -0800
> >> Cc: Denis Zubarev <dvzubarev@yandex.ru>,
> >> 67117@debbugs.gnu.org
> >>
> >>
> >>>> Steps to reproduce the issue:
> >>>> 1. emacs -Q
> >>>> 2. M-x find-file /tmp/t.py
> >>>> 3. paste to the buffer
> >>>>
> >>>> Temp(1, 2)
> >>>>
> >>>> 4. M-x python-ts-mode
> >>>> 5. Call search-subtree with backward flag
> >>>> M-x eval-expression (treesit-search-subtree
> >>>> (treesit--thing-at (point) "call")
> >>>> (lambda (n) (equal (treesit-node-type n ) "integer"))
> >>>> t)
> >>>> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
> >>>
> >>> Yuan, any comments to the patch and the issue in general?
> >>
> >> LGTM. Thanks Denis, and Eli :-)
> >
> > Should we install this on the emacs-29 branch or on master?
>
> Emacs-29, I’d say, since it’s a bug fix.
I see that the added tests use treesit--thing-at, which is not
available on the emacs-29 branch. So either we install the tests on
master, or we replace treesit--thing-at in the tests with its body.
WDYT?
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 9:15 ` Eli Zaretskii
@ 2023-11-19 11:25 ` Denis Zubarev
2023-11-19 11:45 ` Eli Zaretskii
0 siblings, 1 reply; 20+ messages in thread
From: Denis Zubarev @ 2023-11-19 11:25 UTC (permalink / raw)
To: Eli Zaretskii, Yuan Fu; +Cc: 67117@debbugs.gnu.org
[-- Attachment #1: Type: text/html, Size: 2497 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Fix-an-issue-when-searching-subtree-backward.patch --]
[-- Type: text/x-diff; name="0002-Fix-an-issue-when-searching-subtree-backward.patch", Size: 3050 bytes --]
From 040a8ad75625ea4e4277fbce920f84a83e15190e Mon Sep 17 00:00:00 2001
From: Denis Zubarev <dvzubarev@yandex.ru>
Date: Sun, 12 Nov 2023 01:42:42 +0300
Subject: [PATCH] Fix an issue when searching subtree backward
* 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
---
src/treesit.c | 4 ++--
test/src/treesit-tests.el | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/treesit.c b/src/treesit.c
index 69b59fca11..4dcad751f4 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3247,9 +3247,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 791e902bd0..6c3b1eed98 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -1167,6 +1167,40 @@ treesit-defun-navigation-top-level
treesit--ert-defun-navigation-top-level-master
'top-level))
+(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))
+ (pcase-let* ((`((,_ . ,call-node)) (treesit-query-capture (treesit-buffer-root-node)
+ '((call) @c)))
+ (node (treesit-search-subtree
+ call-node
+ (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))
+ (pcase-let* ((`((,_ . ,call-node)) (treesit-query-capture (treesit-buffer-root-node)
+ '((call) @c)))
+ (node (treesit-search-subtree
+ call-node
+ (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
--
2.34.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 11:25 ` Denis Zubarev
@ 2023-11-19 11:45 ` Eli Zaretskii
2023-12-19 0:24 ` Denis Zubarev
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-19 11:45 UTC (permalink / raw)
To: Denis Zubarev; +Cc: 67117, casouri
> From: Denis Zubarev <dvzubarev@yandex.ru>
> Cc: "67117@debbugs.gnu.org" <67117@debbugs.gnu.org>
> Date: Sun, 19 Nov 2023 14:25:14 +0300
>
> I replaced use of `treesit--thing-at` with `treesit-query-capture`, so it should be compatible with
> emacs-29
Thanks. Now we need to wait for your copyright assignment paperwork
to complete, which I hope will happen soon, and then we can install
the changeset.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 6:40 ` Eli Zaretskii
@ 2023-11-21 4:23 ` Yuan Fu
2023-11-21 11:43 ` Eli Zaretskii
0 siblings, 1 reply; 20+ messages in thread
From: Yuan Fu @ 2023-11-21 4:23 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 67117, dvzubarev
> On Nov 18, 2023, at 10:40 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 18 Nov 2023 22:13:49 -0800
>> Cc: dvzubarev@yandex.ru,
>> 67117@debbugs.gnu.org
>>
>>
>>
>>> On Nov 18, 2023, at 9:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>>>
>>>> From: Yuan Fu <casouri@gmail.com>
>>>> Date: Sat, 18 Nov 2023 10:47:47 -0800
>>>> Cc: Denis Zubarev <dvzubarev@yandex.ru>,
>>>> 67117@debbugs.gnu.org
>>>>
>>>>
>>>>>> Steps to reproduce the issue:
>>>>>> 1. emacs -Q
>>>>>> 2. M-x find-file /tmp/t.py
>>>>>> 3. paste to the buffer
>>>>>>
>>>>>> Temp(1, 2)
>>>>>>
>>>>>> 4. M-x python-ts-mode
>>>>>> 5. Call search-subtree with backward flag
>>>>>> M-x eval-expression (treesit-search-subtree
>>>>>> (treesit--thing-at (point) "call")
>>>>>> (lambda (n) (equal (treesit-node-type n ) "integer"))
>>>>>> t)
>>>>>> It should return the second int node (#<treesit-node integer in 9-10>), but it returns nil.
>>>>>
>>>>> Yuan, any comments to the patch and the issue in general?
>>>>
>>>> LGTM. Thanks Denis, and Eli :-)
>>>
>>> Should we install this on the emacs-29 branch or on master?
>>
>> Emacs-29, I’d say, since it’s a bug fix. Why do you ask?
>
> Because I want to install it, obviously.
Of course ;-) I mean you are usually the people who answer this type of questions, and our convention is to install bug fixes on emacs-29, so I was wondering if there’s some other considerations that I don’t know about.
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-21 4:23 ` Yuan Fu
@ 2023-11-21 11:43 ` Eli Zaretskii
2023-11-25 3:44 ` Yuan Fu
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2023-11-21 11:43 UTC (permalink / raw)
To: Yuan Fu; +Cc: 67117, dvzubarev
> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 20 Nov 2023 20:23:33 -0800
> Cc: dvzubarev@yandex.ru,
> 67117@debbugs.gnu.org
>
> >>> Should we install this on the emacs-29 branch or on master?
> >>
> >> Emacs-29, I’d say, since it’s a bug fix. Why do you ask?
> >
> > Because I want to install it, obviously.
>
> Of course ;-) I mean you are usually the people who answer this type of questions, and our convention is to install bug fixes on emacs-29, so I was wondering if there’s some other considerations that I don’t know about.
treesit.c and treesit.el got, and keep getting, significant changes on
the master branch, so when people report bugs for Emacs 30, I cannot
always be sure that the bug exists on the release branch as well, nor
that the patch is appropriate for the release branch (i.e. doesn't
modify code that is different on master). That's why I asked.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-21 11:43 ` Eli Zaretskii
@ 2023-11-25 3:44 ` Yuan Fu
0 siblings, 0 replies; 20+ messages in thread
From: Yuan Fu @ 2023-11-25 3:44 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 67117, Denis Zubarev
> On Nov 21, 2023, at 3:43 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 20 Nov 2023 20:23:33 -0800
>> Cc: dvzubarev@yandex.ru,
>> 67117@debbugs.gnu.org
>>
>>>>> Should we install this on the emacs-29 branch or on master?
>>>>
>>>> Emacs-29, I’d say, since it’s a bug fix. Why do you ask?
>>>
>>> Because I want to install it, obviously.
>>
>> Of course ;-) I mean you are usually the people who answer this type of questions, and our convention is to install bug fixes on emacs-29, so I was wondering if there’s some other considerations that I don’t know about.
>
> treesit.c and treesit.el got, and keep getting, significant changes on
> the master branch, so when people report bugs for Emacs 30, I cannot
> always be sure that the bug exists on the release branch as well, nor
> that the patch is appropriate for the release branch (i.e. doesn't
> modify code that is different on master). That's why I asked.
Ah, right. That makes sense.
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-11-19 11:45 ` Eli Zaretskii
@ 2023-12-19 0:24 ` Denis Zubarev
2023-12-19 2:26 ` Yuan Fu
2023-12-19 3:24 ` Eli Zaretskii
0 siblings, 2 replies; 20+ messages in thread
From: Denis Zubarev @ 2023-12-19 0:24 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 67117@debbugs.gnu.org, casouri@gmail.com
[-- Attachment #1: Type: text/html, Size: 837 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-12-19 0:24 ` Denis Zubarev
@ 2023-12-19 2:26 ` Yuan Fu
2023-12-19 16:52 ` Eli Zaretskii
2023-12-19 3:24 ` Eli Zaretskii
1 sibling, 1 reply; 20+ messages in thread
From: Yuan Fu @ 2023-12-19 2:26 UTC (permalink / raw)
To: Denis Zubarev; +Cc: Eli Zaretskii, 67117-done
> On Dec 18, 2023, at 4:24 PM, Denis Zubarev <dvzubarev@yandex.ru> wrote:
>
> Just FYI, my paperwork is done.
>
Great, applied! Closing this bug.
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-12-19 0:24 ` Denis Zubarev
2023-12-19 2:26 ` Yuan Fu
@ 2023-12-19 3:24 ` Eli Zaretskii
1 sibling, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2023-12-19 3:24 UTC (permalink / raw)
To: Denis Zubarev; +Cc: 67117, casouri
> From: Denis Zubarev <dvzubarev@yandex.ru>
> Cc: "casouri@gmail.com" <casouri@gmail.com>,
> "67117@debbugs.gnu.org" <67117@debbugs.gnu.org>
> Date: Tue, 19 Dec 2023 03:24:57 +0300
>
> Just FYI, my paperwork is done.
Yes, I know it for quite some time.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-12-19 2:26 ` Yuan Fu
@ 2023-12-19 16:52 ` Eli Zaretskii
2023-12-19 17:08 ` Denis Zubarev
0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2023-12-19 16:52 UTC (permalink / raw)
To: Yuan Fu; +Cc: 67117, dvzubarev
> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 18 Dec 2023 18:26:30 -0800
> Cc: Eli Zaretskii <eliz@gnu.org>,
> 67117-done@debbugs.gnu.org
>
> > On Dec 18, 2023, at 4:24 PM, Denis Zubarev <dvzubarev@yandex.ru> wrote:
> >
> > Just FYI, my paperwork is done.
> >
>
> Great, applied! Closing this bug.
The new tests fail here:
ELC src/treesit-tests.elc
In end of data:
src/treesit-tests.el:1094:17: Warning: the function `treesit--thing-at' is not known to be defined.
[...]
Test treesit-search-subtree-backward-1 backtrace:
(treesit--thing-at (point) "call")
(treesit-search-subtree (treesit--thing-at (point) "call") #'(lambda
(let ((node (treesit-search-subtree (treesit--thing-at (point) "call
(closure (t) nil (let* ((fn-621 #'treesit-language-available-p) (arg
ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
ert-run-test(#s(ert-test :name treesit-search-subtree-backward-1 :do
ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
ert-run-tests((not (or (tag :unstable) (tag :nativecomp))) #f(compil
ert-run-tests-batch((not (or (tag :unstable) (tag :nativecomp))))
ert-run-tests-batch-and-exit((not (or (tag :unstable) (tag :nativeco
eval((ert-run-tests-batch-and-exit '(not (or (tag :unstable) (tag :n
command-line-1(("-L" ";." "-l" "ert" "-l" "src/treesit-tests.el" "--
command-line()
normal-top-level()
Test treesit-search-subtree-backward-1 condition:
(void-function treesit--thing-at)
FAILED 24/25 treesit-search-subtree-backward-1 (0.000000 sec) at src/treesit-tests.el:1100
Can't guess python-indent-offset, using defaults: 4
Test treesit-search-subtree-forward-1 backtrace:
(treesit--thing-at (point) "call")
(treesit-search-subtree (treesit--thing-at (point) "call") #'(lambda
(let ((node (treesit-search-subtree (treesit--thing-at (point) "call
(closure (t) nil (let* ((fn-609 #'treesit-language-available-p) (arg
ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
ert-run-test(#s(ert-test :name treesit-search-subtree-forward-1 :doc
ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
ert-run-tests((not (or (tag :unstable) (tag :nativecomp))) #f(compil
ert-run-tests-batch((not (or (tag :unstable) (tag :nativecomp))))
ert-run-tests-batch-and-exit((not (or (tag :unstable) (tag :nativeco
eval((ert-run-tests-batch-and-exit '(not (or (tag :unstable) (tag :n
command-line-1(("-L" ";." "-l" "ert" "-l" "src/treesit-tests.el" "--
command-line()
normal-top-level()
Test treesit-search-subtree-forward-1 condition:
(void-function treesit--thing-at)
FAILED 25/25 treesit-search-subtree-forward-1 (0.015625 sec) at src/treesit-tests.el:1086
The function treesit--thing-at is only available on master.
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-12-19 16:52 ` Eli Zaretskii
@ 2023-12-19 17:08 ` Denis Zubarev
2023-12-23 7:09 ` Yuan Fu
0 siblings, 1 reply; 20+ messages in thread
From: Denis Zubarev @ 2023-12-19 17:08 UTC (permalink / raw)
To: Eli Zaretskii, Yuan Fu; +Cc: 67117@debbugs.gnu.org
[-- Attachment #1: Type: text/html, Size: 3944 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Fix-an-issue-when-searching-subtree-backward.patch --]
[-- Type: text/x-diff; name="0002-Fix-an-issue-when-searching-subtree-backward.patch", Size: 3050 bytes --]
From 040a8ad75625ea4e4277fbce920f84a83e15190e Mon Sep 17 00:00:00 2001
From: Denis Zubarev <dvzubarev@yandex.ru>
Date: Sun, 12 Nov 2023 01:42:42 +0300
Subject: [PATCH] Fix an issue when searching subtree backward
* 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
---
src/treesit.c | 4 ++--
test/src/treesit-tests.el | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/treesit.c b/src/treesit.c
index 69b59fca11..4dcad751f4 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3247,9 +3247,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 791e902bd0..6c3b1eed98 100644
--- a/test/src/treesit-tests.el
+++ b/test/src/treesit-tests.el
@@ -1167,6 +1167,40 @@ treesit-defun-navigation-top-level
treesit--ert-defun-navigation-top-level-master
'top-level))
+(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))
+ (pcase-let* ((`((,_ . ,call-node)) (treesit-query-capture (treesit-buffer-root-node)
+ '((call) @c)))
+ (node (treesit-search-subtree
+ call-node
+ (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))
+ (pcase-let* ((`((,_ . ,call-node)) (treesit-query-capture (treesit-buffer-root-node)
+ '((call) @c)))
+ (node (treesit-search-subtree
+ call-node
+ (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
--
2.34.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-12-19 17:08 ` Denis Zubarev
@ 2023-12-23 7:09 ` Yuan Fu
2023-12-26 0:39 ` Yuan Fu
0 siblings, 1 reply; 20+ messages in thread
From: Yuan Fu @ 2023-12-23 7:09 UTC (permalink / raw)
To: Denis Zubarev; +Cc: 67117@debbugs.gnu.org, Eli Zaretskii
> On Dec 19, 2023, at 9:08 AM, Denis Zubarev <dvzubarev@yandex.ru> wrote:
>
> I replaced treesit--thing-at with the function from emacs 29.1 in the last version of the patch.
> Attached it here.
> 19.12.2023, 19:53, "Eli Zaretskii" <eliz@gnu.org>:
> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 18 Dec 2023 18:26:30 -0800
> Cc: Eli Zaretskii <eliz@gnu.org>,
> 67117-done@debbugs.gnu.org
>
> > On Dec 18, 2023, at 4:24 PM, Denis Zubarev <dvzubarev@yandex.ru> wrote:
> >
> > Just FYI, my paperwork is done.
> >
>
> Great, applied! Closing this bug.
>
> The new tests fail here:
>
> ELC src/treesit-tests.elc
>
> In end of data:
> src/treesit-tests.el:1094:17: Warning: the function `treesit--thing-at' is not known to be defined.
> [...]
> Test treesit-search-subtree-backward-1 backtrace:
> (treesit--thing-at (point) "call")
> (treesit-search-subtree (treesit--thing-at (point) "call") #'(lambda
> (let ((node (treesit-search-subtree (treesit--thing-at (point) "call
> (closure (t) nil (let* ((fn-621 #'treesit-language-available-p) (arg
> ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
> ert-run-test(#s(ert-test :name treesit-search-subtree-backward-1 :do
> ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
> ert-run-tests((not (or (tag :unstable) (tag :nativecomp))) #f(compil
> ert-run-tests-batch((not (or (tag :unstable) (tag :nativecomp))))
> ert-run-tests-batch-and-exit((not (or (tag :unstable) (tag :nativeco
> eval((ert-run-tests-batch-and-exit '(not (or (tag :unstable) (tag :n
> command-line-1(("-L" ";." "-l" "ert" "-l" "src/treesit-tests.el" "--
> command-line()
> normal-top-level()
> Test treesit-search-subtree-backward-1 condition:
> (void-function treesit--thing-at)
> FAILED 24/25 treesit-search-subtree-backward-1 (0.000000 sec) at src/treesit-tests.el:1100
> Can't guess python-indent-offset, using defaults: 4
> Test treesit-search-subtree-forward-1 backtrace:
> (treesit--thing-at (point) "call")
> (treesit-search-subtree (treesit--thing-at (point) "call") #'(lambda
> (let ((node (treesit-search-subtree (treesit--thing-at (point) "call
> (closure (t) nil (let* ((fn-609 #'treesit-language-available-p) (arg
> ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
> ert-run-test(#s(ert-test :name treesit-search-subtree-forward-1 :doc
> ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
> ert-run-tests((not (or (tag :unstable) (tag :nativecomp))) #f(compil
> ert-run-tests-batch((not (or (tag :unstable) (tag :nativecomp))))
> ert-run-tests-batch-and-exit((not (or (tag :unstable) (tag :nativeco
> eval((ert-run-tests-batch-and-exit '(not (or (tag :unstable) (tag :n
> command-line-1(("-L" ";." "-l" "ert" "-l" "src/treesit-tests.el" "--
> command-line()
> normal-top-level()
> Test treesit-search-subtree-forward-1 condition:
> (void-function treesit--thing-at)
> FAILED 25/25 treesit-search-subtree-forward-1 (0.015625 sec) at src/treesit-tests.el:1086
>
> The function treesit--thing-at is only available on master.<0002-Fix-an-issue-when-searching-subtree-backward.patch>
Thanks, applied this patch, and all tests pass now.
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward
2023-12-23 7:09 ` Yuan Fu
@ 2023-12-26 0:39 ` Yuan Fu
0 siblings, 0 replies; 20+ messages in thread
From: Yuan Fu @ 2023-12-26 0:39 UTC (permalink / raw)
To: Denis Zubarev; +Cc: Eli Zaretskii, 67117-done
>
> Thanks, applied this patch, and all tests pass now.
>
> Yuan
>
Closing this report.
Yuan
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2023-12-26 0:39 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-11 23:38 bug#67117: [PATCH] Tree-sitter: fix an issue when searching subtree backward Denis Zubarev
2023-11-15 13:21 ` Eli Zaretskii
2023-11-15 17:01 ` Eli Zaretskii
2023-11-18 18:47 ` Yuan Fu
2023-11-19 5:47 ` Eli Zaretskii
2023-11-19 6:13 ` Yuan Fu
2023-11-19 6:40 ` Eli Zaretskii
2023-11-21 4:23 ` Yuan Fu
2023-11-21 11:43 ` Eli Zaretskii
2023-11-25 3:44 ` Yuan Fu
2023-11-19 9:15 ` Eli Zaretskii
2023-11-19 11:25 ` Denis Zubarev
2023-11-19 11:45 ` Eli Zaretskii
2023-12-19 0:24 ` Denis Zubarev
2023-12-19 2:26 ` Yuan Fu
2023-12-19 16:52 ` Eli Zaretskii
2023-12-19 17:08 ` Denis Zubarev
2023-12-23 7:09 ` Yuan Fu
2023-12-26 0:39 ` Yuan Fu
2023-12-19 3:24 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.