diff options
| author | Yuan Fu | 2022-11-25 18:50:26 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-11-25 19:00:22 -0800 |
| commit | 0369dcacf30aff6d4f733872058fa2446330fd02 (patch) | |
| tree | d8d8cc56a4801bed293d23c48ce97e8562df014d /src | |
| parent | 4ffca85f1eefea5adc96efc276acfae4d737aa17 (diff) | |
| download | emacs-0369dcacf30aff6d4f733872058fa2446330fd02.tar.gz emacs-0369dcacf30aff6d4f733872058fa2446330fd02.zip | |
Fix tree-sitter assertion error (bug#59574)
* src/treesit.c (treesit_sync_visible_region): Initialize
visible_beg/end when tree is NULL.
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/treesit.c b/src/treesit.c index d18e77a3531..c910aea1da2 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -782,13 +782,13 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | |||
| 782 | matches that of the buffer, and update visible_beg/end. | 782 | matches that of the buffer, and update visible_beg/end. |
| 783 | 783 | ||
| 784 | That is, the whole purpose of visible_beg/end (and | 784 | That is, the whole purpose of visible_beg/end (and |
| 785 | treesit_record_change and treesit_sync_visible_region) is to | 785 | treesit_record_change and treesit_sync_visible_region) is to update |
| 786 | update the tree (by ts_tree_edit). So if the tree is NULL, we | 786 | the tree (by ts_tree_edit). So if the tree is NULL, |
| 787 | don't update the tree and there is no need to keep tracking of | 787 | visible_beg/end are considered uninitialized. Only when we already |
| 788 | them. Only when we already have a tree, do we need to keep track | 788 | have a tree, do we need to keep track of position changes and |
| 789 | of position changes and update it correctly, so it can be feed into | 789 | update it correctly, so it can be feed into ts_parser_parse as the |
| 790 | ts_parser_parse as the old tree, so that tree-sitter only parses | 790 | old tree, so that tree-sitter only parses the changed part (aka |
| 791 | the changed part (aka incremental). | 791 | incremental). |
| 792 | 792 | ||
| 793 | In a nutshell, tree-sitter incremental parsing in Emacs looks like: | 793 | In a nutshell, tree-sitter incremental parsing in Emacs looks like: |
| 794 | 794 | ||
| @@ -815,11 +815,17 @@ static void | |||
| 815 | treesit_sync_visible_region (Lisp_Object parser) | 815 | treesit_sync_visible_region (Lisp_Object parser) |
| 816 | { | 816 | { |
| 817 | TSTree *tree = XTS_PARSER (parser)->tree; | 817 | TSTree *tree = XTS_PARSER (parser)->tree; |
| 818 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); | ||
| 818 | 819 | ||
| 820 | /* If we are setting visible_beg/end for the first time, we can skip | ||
| 821 | the offset acrobatics and updating the tree below. */ | ||
| 819 | if (tree == NULL) | 822 | if (tree == NULL) |
| 820 | return; | 823 | { |
| 824 | XTS_PARSER (parser)->visible_beg = BUF_BEGV_BYTE (buffer); | ||
| 825 | XTS_PARSER (parser)->visible_end = BUF_ZV_BYTE (buffer); | ||
| 826 | return; | ||
| 827 | } | ||
| 821 | 828 | ||
| 822 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); | ||
| 823 | ptrdiff_t visible_beg = XTS_PARSER (parser)->visible_beg; | 829 | ptrdiff_t visible_beg = XTS_PARSER (parser)->visible_beg; |
| 824 | ptrdiff_t visible_end = XTS_PARSER (parser)->visible_end; | 830 | ptrdiff_t visible_end = XTS_PARSER (parser)->visible_end; |
| 825 | eassert (0 <= visible_beg); | 831 | eassert (0 <= visible_beg); |