diff options
| author | Eli Zaretskii | 2022-11-29 13:55:31 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2022-11-29 13:55:31 +0200 |
| commit | 067c65578e02034d7605f1dcaf6a6d0c4bbdbda3 (patch) | |
| tree | 455bd2ac2c0953b1778d2cc9bb71f383db751712 /src | |
| parent | 78663ad78b83c2a5360f9eb4609af0fab192c340 (diff) | |
| parent | 4313279e34538899cec3a9d8b9c3ca4eaffced6a (diff) | |
| download | emacs-067c65578e02034d7605f1dcaf6a6d0c4bbdbda3.tar.gz emacs-067c65578e02034d7605f1dcaf6a6d0c4bbdbda3.zip | |
Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/emacs into emacs-29
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/treesit.c b/src/treesit.c index 69272b8ad88..4b150059fac 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -810,7 +810,10 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | |||
| 810 | with BUF_BEGV_BYTE and BUG_ZV_BYTE. When calling this function you | 810 | with BUF_BEGV_BYTE and BUG_ZV_BYTE. When calling this function you |
| 811 | must make sure the current buffer's size in bytes is not larger than | 811 | must make sure the current buffer's size in bytes is not larger than |
| 812 | UINT32_MAX. Basically, always call treesit_check_buffer_size before | 812 | UINT32_MAX. Basically, always call treesit_check_buffer_size before |
| 813 | this function. */ | 813 | this function. |
| 814 | |||
| 815 | If buffer range changed since last parse (visible_beg/end doesn't | ||
| 816 | match buffer visible beginning/end), set need_reparse to true. */ | ||
| 814 | static void | 817 | static void |
| 815 | treesit_sync_visible_region (Lisp_Object parser) | 818 | treesit_sync_visible_region (Lisp_Object parser) |
| 816 | { | 819 | { |
| @@ -834,6 +837,12 @@ treesit_sync_visible_region (Lisp_Object parser) | |||
| 834 | eassert (BUF_BEGV_BYTE (buffer) <= UINT32_MAX); | 837 | eassert (BUF_BEGV_BYTE (buffer) <= UINT32_MAX); |
| 835 | eassert (BUF_ZV_BYTE (buffer) <= UINT32_MAX); | 838 | eassert (BUF_ZV_BYTE (buffer) <= UINT32_MAX); |
| 836 | 839 | ||
| 840 | /* If buffer restriction changed and user requests for a node (hence | ||
| 841 | this function is called), we need to reparse. */ | ||
| 842 | if (visible_beg != BUF_BEGV_BYTE (buffer) | ||
| 843 | || visible_end != BUF_ZV_BYTE (buffer)) | ||
| 844 | XTS_PARSER (parser)->need_reparse = true; | ||
| 845 | |||
| 837 | /* Before we parse or set ranges, catch up with the narrowing | 846 | /* Before we parse or set ranges, catch up with the narrowing |
| 838 | situation. We change visible_beg and visible_end to match | 847 | situation. We change visible_beg and visible_end to match |
| 839 | BUF_BEGV_BYTE and BUF_ZV_BYTE, and inform tree-sitter of the | 848 | BUF_BEGV_BYTE and BUF_ZV_BYTE, and inform tree-sitter of the |
| @@ -879,6 +888,8 @@ treesit_sync_visible_region (Lisp_Object parser) | |||
| 879 | } | 888 | } |
| 880 | eassert (0 <= visible_beg); | 889 | eassert (0 <= visible_beg); |
| 881 | eassert (visible_beg <= visible_end); | 890 | eassert (visible_beg <= visible_end); |
| 891 | eassert (visible_beg == BUF_BEGV_BYTE (buffer)); | ||
| 892 | eassert (visible_end == BUF_ZV_BYTE (buffer)); | ||
| 882 | 893 | ||
| 883 | XTS_PARSER (parser)->visible_beg = visible_beg; | 894 | XTS_PARSER (parser)->visible_beg = visible_beg; |
| 884 | XTS_PARSER (parser)->visible_end = visible_end; | 895 | XTS_PARSER (parser)->visible_end = visible_end; |
| @@ -922,17 +933,20 @@ treesit_call_after_change_functions (TSTree *old_tree, TSTree *new_tree, | |||
| 922 | static void | 933 | static void |
| 923 | treesit_ensure_parsed (Lisp_Object parser) | 934 | treesit_ensure_parsed (Lisp_Object parser) |
| 924 | { | 935 | { |
| 925 | if (!XTS_PARSER (parser)->need_reparse) | ||
| 926 | return; | ||
| 927 | TSParser *treesit_parser = XTS_PARSER (parser)->parser; | ||
| 928 | TSTree *tree = XTS_PARSER (parser)->tree; | ||
| 929 | TSInput input = XTS_PARSER (parser)->input; | ||
| 930 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); | 936 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); |
| 931 | 937 | ||
| 932 | /* Before we parse, catch up with the narrowing situation. */ | 938 | /* Before we parse, catch up with the narrowing situation. */ |
| 933 | treesit_check_buffer_size (buffer); | 939 | treesit_check_buffer_size (buffer); |
| 940 | /* This function has to run before we check for need_reparse flag, | ||
| 941 | because it might set the flag to true. */ | ||
| 934 | treesit_sync_visible_region (parser); | 942 | treesit_sync_visible_region (parser); |
| 935 | 943 | ||
| 944 | if (!XTS_PARSER (parser)->need_reparse) | ||
| 945 | return; | ||
| 946 | TSParser *treesit_parser = XTS_PARSER (parser)->parser; | ||
| 947 | TSTree *tree = XTS_PARSER (parser)->tree; | ||
| 948 | TSInput input = XTS_PARSER (parser)->input; | ||
| 949 | |||
| 936 | TSTree *new_tree = ts_parser_parse (treesit_parser, tree, input); | 950 | TSTree *new_tree = ts_parser_parse (treesit_parser, tree, input); |
| 937 | /* This should be very rare (impossible, really): it only happens | 951 | /* This should be very rare (impossible, really): it only happens |
| 938 | when 1) language is not set (impossible in Emacs because the user | 952 | when 1) language is not set (impossible in Emacs because the user |