aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuan Fu2022-12-05 18:37:47 -0800
committerYuan Fu2022-12-05 19:56:47 -0800
commitc26fe45cb8046eecaf3a74e3e7d4bc62ab511a8c (patch)
tree3cdc961f440fa79f0d9c48901c9f961d525787a8 /src
parent318bf42b410d4a8ecf0e8ff64280cfd655884877 (diff)
downloademacs-c26fe45cb8046eecaf3a74e3e7d4bc62ab511a8c.tar.gz
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')
-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. */)
2507 /* Set query range. */ 2507 /* Set query range. */
2508 if (!NILP (beg) && !NILP (end)) 2508 if (!NILP (beg) && !NILP (end))
2509 { 2509 {
2510 EMACS_INT beg_byte = XFIXNUM (beg); 2510 EMACS_INT beg_byte = buf_charpos_to_bytepos (current_buffer,
2511 EMACS_INT end_byte = XFIXNUM (end); 2511 XFIXNUM (beg));
2512 EMACS_INT end_byte = buf_charpos_to_bytepos (current_buffer,
2513 XFIXNUM (end));
2512 /* We never let tree-sitter run on buffers too large, so these 2514 /* We never let tree-sitter run on buffers too large, so these
2513 assertion should never hit. */ 2515 assertion should never hit. */
2514 eassert (beg_byte - visible_beg <= UINT32_MAX); 2516 eassert (beg_byte - visible_beg <= UINT32_MAX);
2515 eassert (end_byte - visible_beg <= UINT32_MAX); 2517 eassert (end_byte - visible_beg <= UINT32_MAX);
2516 ts_query_cursor_set_byte_range (cursor, (uint32_t) beg_byte - visible_beg, 2518 ts_query_cursor_set_byte_range (cursor,
2517 (uint32_t) end_byte - visible_beg); 2519 (uint32_t) (beg_byte - visible_beg),
2520 (uint32_t) (end_byte - visible_beg));
2518 } 2521 }
2519 2522
2520 /* Execute query. */ 2523 /* Execute query. */