Subject: Re: bug#67977: 30.0.50; tree-sitter: Emacs crashes when accessing treesit-nodes in a narrowed buffer

From: Yuan Fu <[email-masked]>
Date: Sat, 30 Dec 2023 12:23:18 -0800

> On Dec 30, 2023, at 8:21 AM, Denis Zubarev <[email-masked]> wrote:
> 
> > I pushed a fix and now it shouldn’t crash anymore. However, I’m yet not sure why at some point the buffer was widened. Is there any way to track who called widen?
>  Thank you, It doesn't crash anymore.
>  > So it seems working in a narrowed buffer would trigger a lot of back-and-fortch reparse. I wonder if it’s worth optimizing for (eg, use two parsers behind the scenes, one for widened buffer and one for narrowed buffer).
>  I have performed a quite naive benchmark and haven't seen any significant slow down when inserting text in a narrowed buffer.

Right, when you type, since the only thing that access the parser is font-lock, which always widens the buffer, there’s no unnecessary reparse. If you invoke some function that access the parser while the buffer is narrowed, that’ll trigger a reparse, and the next time font-lock runs, it’ll widen and make the parser reparse the full buffer again.

Yuan