summaryrefslogtreecommitdiff
path: root/src/treesit.c
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2022-12-05 18:37:47 -0800
committerYuan Fu <casouri@gmail.com>2022-12-05 19:56:47 -0800
commitc26fe45cb8046eecaf3a74e3e7d4bc62ab511a8c (patch)
tree3cdc961f440fa79f0d9c48901c9f961d525787a8 /src/treesit.c
parent318bf42b410d4a8ecf0e8ff64280cfd655884877 (diff)
downloademacs-c26fe45cb8046eecaf3a74e3e7d4bc62ab511a8c.tar.gz
emacs-c26fe45cb8046eecaf3a74e3e7d4bc62ab511a8c.tar.bz2
emacs-c26fe45cb8046eecaf3a74e3e7d4bc62ab511a8c.zip
Fix treesit-query-capture
Before this change Ftreesit_query_capture doesn't convert character position to byte position for BEG and END parameters. I observed fontification issue in css files but couldn't figure out why, now I know :-) I decide to keep treesit--font-lock-query-expand-range, since it might provide a escape hatch for problems we discover in the future, and it should be very cheap so no downside of keeping it. * lisp/textmodes/css-mode.el (css-ts-mode): Stop setting treesit--font-lock-query-expand-range. * lisp/treesit.el (treesit--font-lock-query-expand-range): Update docstring. * src/treesit.c (Ftreesit_query_capture): Convert BEG and END to byte position. Also added parentheses wround "beg_byte - visible_beg" in the call to ts_query_cursor_set_byte_range (i.e., style change).
Diffstat (limited to 'src/treesit.c')
-rw-r--r--src/treesit.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 4b150059fac..343054ed53e 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -2507,14 +2507,17 @@ the query. */)
/* Set query range. */
if (!NILP (beg) && !NILP (end))
{
- EMACS_INT beg_byte = XFIXNUM (beg);
- EMACS_INT end_byte = XFIXNUM (end);
+ EMACS_INT beg_byte = buf_charpos_to_bytepos (current_buffer,
+ XFIXNUM (beg));
+ EMACS_INT end_byte = buf_charpos_to_bytepos (current_buffer,
+ XFIXNUM (end));
/* We never let tree-sitter run on buffers too large, so these
assertion should never hit. */
eassert (beg_byte - visible_beg <= UINT32_MAX);
eassert (end_byte - visible_beg <= UINT32_MAX);
- ts_query_cursor_set_byte_range (cursor, (uint32_t) beg_byte - visible_beg,
- (uint32_t) end_byte - visible_beg);
+ ts_query_cursor_set_byte_range (cursor,
+ (uint32_t) (beg_byte - visible_beg),
+ (uint32_t) (end_byte - visible_beg));
}
/* Execute query. */