diff options
| author | Yuan Fu | 2023-12-23 16:47:04 -0800 |
|---|---|---|
| committer | Yuan Fu | 2023-12-23 18:43:51 -0800 |
| commit | 683c7c96871cc374b0e00f5084e43a70fc3ec36a (patch) | |
| tree | 1760611714cff37dae563e0b37be9925792d2a5b /src | |
| parent | 8ae42c825e1e058d3c736837a023bdc2617b85a2 (diff) | |
| download | emacs-683c7c96871cc374b0e00f5084e43a70fc3ec36a.tar.gz emacs-683c7c96871cc374b0e00f5084e43a70fc3ec36a.zip | |
Increment parser timestamp when narrowing changes (bug#67977)
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 6 | ||||
| -rw-r--r-- | src/treesit.h | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/treesit.c b/src/treesit.c index 93ed97212d7..879405e551a 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -931,7 +931,10 @@ treesit_sync_visible_region (Lisp_Object parser) | |||
| 931 | this function is called), we need to reparse. */ | 931 | this function is called), we need to reparse. */ |
| 932 | if (visible_beg != BUF_BEGV_BYTE (buffer) | 932 | if (visible_beg != BUF_BEGV_BYTE (buffer) |
| 933 | || visible_end != BUF_ZV_BYTE (buffer)) | 933 | || visible_end != BUF_ZV_BYTE (buffer)) |
| 934 | XTS_PARSER (parser)->need_reparse = true; | 934 | { |
| 935 | XTS_PARSER (parser)->need_reparse = true; | ||
| 936 | XTS_PARSER (parser)->timestamp++; | ||
| 937 | } | ||
| 935 | 938 | ||
| 936 | /* Before we parse or set ranges, catch up with the narrowing | 939 | /* Before we parse or set ranges, catch up with the narrowing |
| 937 | situation. We change visible_beg and visible_end to match | 940 | situation. We change visible_beg and visible_end to match |
| @@ -1671,6 +1674,7 @@ buffer. */) | |||
| 1671 | ranges); | 1674 | ranges); |
| 1672 | 1675 | ||
| 1673 | XTS_PARSER (parser)->need_reparse = true; | 1676 | XTS_PARSER (parser)->need_reparse = true; |
| 1677 | XTS_PARSER (parser)->timestamp++; | ||
| 1674 | return Qnil; | 1678 | return Qnil; |
| 1675 | } | 1679 | } |
| 1676 | 1680 | ||
diff --git a/src/treesit.h b/src/treesit.h index 5382bc58817..3d59262b53a 100644 --- a/src/treesit.h +++ b/src/treesit.h | |||
| @@ -53,7 +53,9 @@ struct Lisp_TS_Parser | |||
| 53 | /* Re-parsing an unchanged buffer is not free for tree-sitter, so we | 53 | /* Re-parsing an unchanged buffer is not free for tree-sitter, so we |
| 54 | only make it re-parse when need_reparse == true. That usually | 54 | only make it re-parse when need_reparse == true. That usually |
| 55 | means some change is made in the buffer. But others could set | 55 | means some change is made in the buffer. But others could set |
| 56 | this field to true to force tree-sitter to re-parse. */ | 56 | this field to true to force tree-sitter to re-parse. When you |
| 57 | set this to true, you should _always_ also increment | ||
| 58 | timestamp. */ | ||
| 57 | bool need_reparse; | 59 | bool need_reparse; |
| 58 | /* These two positions record the buffer byte position (1-based) of | 60 | /* These two positions record the buffer byte position (1-based) of |
| 59 | the "visible region" that tree-sitter sees. Before re-parse, we | 61 | the "visible region" that tree-sitter sees. Before re-parse, we |