]> git.eshelyaron.com Git - emacs.git/commitdiff
Increment parser timestamp when narrowing changes (bug#67977)
authorYuan Fu <casouri@gmail.com>
Sun, 24 Dec 2023 00:47:04 +0000 (16:47 -0800)
committerEshel Yaron <me@eshelyaron.com>
Tue, 2 Jan 2024 07:16:06 +0000 (08:16 +0100)
When narrowing changes, parse reparses, so the timestamp should
definitely increment, just like in ts_record_changes.

Failing to increment this timestamp, outdated nodes would think they
are still up-to-date, and try to print their type name.  Printing
their type name involves accessing the old parse tree, which is
already freed during the last reparse.

I also found that we don't increment timestamp when changing parser
ranges and fixed that as well.

* src/treesit.c (treesit_sync_visible_region):
(Ftreesit_parser_set_included_ranges): Increment timestamp.
* src/treesit.h (Lisp_TS_Parser): Add some comments.

(cherry picked from commit 683c7c96871cc374b0e00f5084e43a70fc3ec36a)

src/treesit.c
src/treesit.h

index c65873a28f787e71d6a56fa7dea9676f7f41ae5e..f161b748fd9a0a771d81acfaa54cefdc45d71073 100644 (file)
@@ -948,7 +948,10 @@ treesit_sync_visible_region (Lisp_Object parser)
      this function is called), we need to reparse.  */
   if (visible_beg != BUF_BEGV_BYTE (buffer)
       || visible_end != BUF_ZV_BYTE (buffer))
-    XTS_PARSER (parser)->need_reparse = true;
+    {
+      XTS_PARSER (parser)->need_reparse = true;
+      XTS_PARSER (parser)->timestamp++;
+    }
 
   /* Before we parse or set ranges, catch up with the narrowing
      situation.  We change visible_beg and visible_end to match
@@ -1722,6 +1725,7 @@ buffer.  */)
              ranges);
 
   XTS_PARSER (parser)->need_reparse = true;
+  XTS_PARSER (parser)->timestamp++;
   return Qnil;
 }
 
index ef7e2e153174938384fb2eb0012083f30053ed12..75d3ed778c421e4095e76453bff216a476897e70 100644 (file)
@@ -61,7 +61,9 @@ struct Lisp_TS_Parser
   /* Re-parsing an unchanged buffer is not free for tree-sitter, so we
      only make it re-parse when need_reparse == true.  That usually
      means some change is made in the buffer.  But others could set
-     this field to true to force tree-sitter to re-parse.  */
+     this field to true to force tree-sitter to re-parse.  When you
+     set this to true, you should _always_ also increment
+     timestamp.  */
   bool need_reparse;
   /* These two positions record the buffer byte position (1-based) of
      the "visible region" that tree-sitter sees.  Before re-parse, we