diff options
| author | Yuan Fu | 2023-02-02 17:22:22 -0800 |
|---|---|---|
| committer | Yuan Fu | 2023-02-02 18:31:19 -0800 |
| commit | 8a6bdf88b4b665916cf74dee3a30e9136a9b6df8 (patch) | |
| tree | 8deeefbb73149fdf3e5efd4a80321be98f62127e /src | |
| parent | a2b77c79dcca64b5e0ae58862206e7cc29640944 (diff) | |
| download | emacs-8a6bdf88b4b665916cf74dee3a30e9136a9b6df8.tar.gz emacs-8a6bdf88b4b665916cf74dee3a30e9136a9b6df8.zip | |
Call treesit_record_change in insert_from_gap_1
Before this change, insert_from_gap calls treesit_record_change but
insert_from_gap_1 doesn't. However, insert_from_gap_1 is a public
function and is called in many other places outside of insdel.c. This
could lead to tree-sitter's parse tree becoming out-of-sync with the
buffer content.
This change might fix bug#60650.
* src/insdel.c (insert_from_gap_1): Call treesit_record_change.
(insert_from_gap): Remove call to treesit_record_change.
* admin/notes/tree-sitter/treesit_record_change: New file.
Diffstat (limited to 'src')
| -rw-r--r-- | src/insdel.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/insdel.c b/src/insdel.c index 0e1e98664b3..e459d0cfa17 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -1101,6 +1101,10 @@ insert_from_gap_1 (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) | |||
| 1101 | eassert (NILP (BVAR (current_buffer, enable_multibyte_characters)) | 1101 | eassert (NILP (BVAR (current_buffer, enable_multibyte_characters)) |
| 1102 | ? nchars == nbytes : nchars <= nbytes); | 1102 | ? nchars == nbytes : nchars <= nbytes); |
| 1103 | 1103 | ||
| 1104 | #ifdef HAVE_TREE_SITTER | ||
| 1105 | ptrdiff_t ins_bytepos = GPT_BYTE; | ||
| 1106 | #endif | ||
| 1107 | |||
| 1104 | GAP_SIZE -= nbytes; | 1108 | GAP_SIZE -= nbytes; |
| 1105 | if (! text_at_gap_tail) | 1109 | if (! text_at_gap_tail) |
| 1106 | { | 1110 | { |
| @@ -1115,6 +1119,12 @@ insert_from_gap_1 (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) | |||
| 1115 | /* Put an anchor to ensure multi-byte form ends at gap. */ | 1119 | /* Put an anchor to ensure multi-byte form ends at gap. */ |
| 1116 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; | 1120 | if (GAP_SIZE > 0) *(GPT_ADDR) = 0; |
| 1117 | eassert (GPT <= GPT_BYTE); | 1121 | eassert (GPT <= GPT_BYTE); |
| 1122 | |||
| 1123 | #ifdef HAVE_TREE_SITTER | ||
| 1124 | eassert (nbytes >= 0); | ||
| 1125 | eassert (ins_bytepos >= 0); | ||
| 1126 | treesit_record_change (ins_bytepos, ins_bytepos, ins_bytepos + nbytes); | ||
| 1127 | #endif | ||
| 1118 | } | 1128 | } |
| 1119 | 1129 | ||
| 1120 | /* Insert a sequence of NCHARS chars which occupy NBYTES bytes | 1130 | /* Insert a sequence of NCHARS chars which occupy NBYTES bytes |
| @@ -1150,12 +1160,6 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) | |||
| 1150 | current_buffer, 0); | 1160 | current_buffer, 0); |
| 1151 | } | 1161 | } |
| 1152 | 1162 | ||
| 1153 | #ifdef HAVE_TREE_SITTER | ||
| 1154 | eassert (nbytes >= 0); | ||
| 1155 | eassert (ins_bytepos >= 0); | ||
| 1156 | treesit_record_change (ins_bytepos, ins_bytepos, ins_bytepos + nbytes); | ||
| 1157 | #endif | ||
| 1158 | |||
| 1159 | if (ins_charpos < PT) | 1163 | if (ins_charpos < PT) |
| 1160 | adjust_point (nchars, nbytes); | 1164 | adjust_point (nchars, nbytes); |
| 1161 | 1165 | ||
| @@ -1191,6 +1195,9 @@ insert_from_buffer (struct buffer *buf, | |||
| 1191 | #endif | 1195 | #endif |
| 1192 | } | 1196 | } |
| 1193 | 1197 | ||
| 1198 | /* NOTE: If we ever make insert_from_buffer_1 public, make sure to | ||
| 1199 | move the call to treesit_record_change into it. */ | ||
| 1200 | |||
| 1194 | static void | 1201 | static void |
| 1195 | insert_from_buffer_1 (struct buffer *buf, | 1202 | insert_from_buffer_1 (struct buffer *buf, |
| 1196 | ptrdiff_t from, ptrdiff_t nchars, bool inherit) | 1203 | ptrdiff_t from, ptrdiff_t nchars, bool inherit) |