]> git.eshelyaron.com Git - emacs.git/commitdiff
Read more on each call to treesit's buffer reader
authorYuan Fu <casouri@gmail.com>
Mon, 9 Sep 2024 00:46:18 +0000 (17:46 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sat, 14 Sep 2024 20:16:24 +0000 (22:16 +0200)
* src/treesit.c (treesit_read_buffer): Read until the gap or visible
end, instead of reading a single char.

(cherry picked from commit bf23382f1f2d6ea072db4e4750f8a345f77a3ef2)

src/treesit.c

index cac1d4b4d11ab9a9fee827639368976855cb8f10..e8eecbc02d194dbb9bf09d1c5f9b559125b37d5d 100644 (file)
@@ -1186,11 +1186,13 @@ treesit_read_buffer (void *parser, uint32_t byte_index,
       beg = NULL;
       len = 0;
     }
-  /* Normal case, read a character.  */
+  /* Normal case, read until the gap or visible end.  */
   else
     {
       beg = (char *) BUF_BYTE_ADDRESS (buffer, byte_pos);
-      len = BYTES_BY_CHAR_HEAD ((int) *beg);
+      ptrdiff_t gap_bytepos = buffer->text->gpt_byte;
+      len = (byte_pos < gap_bytepos)
+           ? gap_bytepos - byte_pos : visible_end - byte_pos;
     }
   /* We never let tree-sitter to parse buffers that large so this
      assertion should never hit.  */