GNU bug report logs - #62333
30.0.50; Issue with tree-sitter syntax tree during certain changes

Previous Next

Package: emacs;

Reported by: Wilhelm Kirschbaum <wkirschbaum <at> gmail.com>

Date: Tue, 21 Mar 2023 14:15:01 UTC

Severity: normal

Found in version 30.0.50

Full log


View this message in rfc822 format

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Wilhelm Kirschbaum <wkirschbaum <at> gmail.com>, 62333 <at> debbugs.gnu.org, Dmitry Gutov <dgutov <at> yandex.ru>
Subject: bug#62333: 30.0.50; Issue with tree-sitter syntax tree during certain changes
Date: Fri, 24 Mar 2023 00:34:58 -0700

> On Mar 23, 2023, at 11:05 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Thu, 23 Mar 2023 16:59:28 -0700
>> Cc: Eli Zaretskii <eliz <at> gnu.org>,
>> Wilhelm Kirschbaum <wkirschbaum <at> gmail.com>,
>> 62333 <at> debbugs.gnu.org
>> 
>>> On Mar 23, 2023, at 3:06 PM, Dmitry Gutov <dgutov <at> yandex.ru> wrote:
>>> 
>>> On 23/03/2023 23:18, Yuan Fu wrote:
>>>> I guess the question now is why redisplay is triggered in blink-matching-open
>>> 
>>> blink-matching-open calls sit-for after adjusting overlays.
>>> 
>>> sit-for starts with a redisplay.
>> 
>> But it’s not called when narrow-to-region is in effect.
> 
> Exactly.  So the question is now: why does treesit.c see ZV changed,
> if by the time it is supposed to be called from redisplay the
> restriction is restored?
> 
> Is the problematic code in treesit.c really called from redisplay
> triggered by sit-for in blink-matching-open?  Can you show the C and
> Lisp backtrace from the call that "sees that BUF_ZV_BYTE is smaller
> than its visible_end"?

Ah, I made a mistake, it isn’t that it doesn’t reproduce on Linux, but rather it doesn’t reproduce on emacs-29. Since I’m able to reproduce it on Linux, I set a breakpoint and the backtrace explains it: blink-match-open calls forward-sexp, which calls elixir-ts—forward-sexp, which accesses the parse tree, which causes tree-sitter to reparse in the narrowed context.

But normally tree-sitter will reparse again when redisplay fontifies the buffer, because now the visible portion is back to the whole buffer. Tree-sitter didn’t do that because I made a mistake when modifying treesit_ensure_parsed. I moved the code that checks for the need_reparse flag before treesit_sync_visible_region, which sets the need_reparse flag if it detects that narrow situation has changed.

Well, this is a bit embarrassing, there is even a comment warning this mistake, but anyway, I pushed a fix, once it gets merged into master, the problem should go away. 

As things stands right now, every time blink-match-open blinks the matching parenthesis, tree-sitter would reparse the buffer twice, that’s not exactly ideal. Blink-match-open’s use of narrowing is legit, and we can’t just automatically widen in tree-sitter functions.

Yuan







This bug report was last modified 2 years and 77 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.