Re: emacs-31 29bbd02347d: Fix treesit_cursor_helper_1 for zero-width nodes (bug#81436)
Yuan Fu <[email protected]> Tue, 28 Jul 2026 03:15:12 -0700
| Newsgroups | gmane.emacs.devel |
|---|---|
| Message-ID | <[email protected]> |
> On Jul 27, 2026, at 12:17 PM, Eli Zaretskii <[email protected]> wrote: > >> From: Michael Albinus <[email protected]> >> Cc: Yuan Fu <[email protected]> >> Date: Mon, 27 Jul 2026 18:19:03 +0200 >> >> Yuan Fu <[email protected]> writes: >> >> Hi, >> >>> branch: emacs-31 >>> commit 29bbd02347da44599cc9778d9d626fc5c8ca4b2e >>> Author: Yuan Fu <[email protected]> >>> Commit: Yuan Fu <[email protected]> >>> >>> Fix treesit_cursor_helper_1 for zero-width nodes (bug#81436) >>> >>> * lisp/treesit.el (treesit--some): Add edebug declare. >>> * src/treesit.c (treesit_cursor_helper_1): Don't use >>> ts_tree_cursor_goto_first_child_for_byte for zero-width nodes. >> >> I'm not sure whether it was *this* commit. However, tree-sitter tests on >> emba fail now: > > It's definitely that commit. On my system, the test crashes due to > infinite recursion. > > I tried to fix that now. Yuan, please see if I got the logic right. Thanks Eli! Your fix is right, the idea is that we try the for_byte variant (skipped if start = end), and if that didn’t find a child, try the normal variant. And here’s a trivial patch that hopefully further explains why we need to skip the call to for_byte variant. Yuan
add-comment.patch
(application/octet-stream, 986 B)
From 84b3f4e500e783b78e758890f48aa5512c9e9181 Mon Sep 17 00:00:00 2001 From: Yuan Fu <[email protected]> Date: Tue, 28 Jul 2026 03:13:28 -0700 Subject: [PATCH] ; * src/treesit.c (treesit_cursor_helper_1): Further explanation. --- src/treesit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/treesit.c b/src/treesit.c index 210fae671b3..66644571f83 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -4263,7 +4263,7 @@ treesit_cursor_helper_1 (TSTreeCursor *cursor, TSNode *target, Also, ts_tree_cursor_goto_first_child_for_byte can't find zero-width nodes (which exist and are legit, e.g., markdown's block_continuation), because a zero-width node can't contain a pos - (end > pos). */ + (end > pos); instead, it'll falsely return the next child. */ if (!((start_pos != end_pos && ts_tree_cursor_goto_first_child_for_byte (cursor, start_pos) != -1) || ts_tree_cursor_goto_first_child (cursor))) -- 2.39.5 (Apple Git-154)