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).
This commit is contained in:
parent
318bf42b41
commit
c26fe45cb8
3 changed files with 8 additions and 15 deletions
|
@ -1839,11 +1839,6 @@ can also be used to fill comments.
|
|||
'((selector comment query keyword)
|
||||
(property constant string)
|
||||
(error variable function operator bracket)))
|
||||
;; Tree-sitter-css, for whatever reason, cannot reliably return
|
||||
;; the captured nodes in a given range (it instead returns the
|
||||
;; nodes preceding range). Before this is fixed in
|
||||
;; tree-sitter-css, use this heuristic as a temporary fix.
|
||||
(setq-local treesit--font-lock-query-expand-range (cons 80 80))
|
||||
(setq-local imenu-create-index-function #'css--treesit-imenu)
|
||||
(setq-local which-func-functions nil)
|
||||
(treesit-major-mode-setup)))
|
||||
|
|
|
@ -545,12 +545,7 @@ This should be a cons cell (START . END). When fontifying a
|
|||
buffer, Emacs will move the start of the query range backward by
|
||||
START amount, and the end of the query range by END amount. Both
|
||||
START and END should be positive integers or 0. This doesn't
|
||||
affect the fontified range.
|
||||
|
||||
Sometimes, querying on some parser with a restricted range
|
||||
returns nodes not in that range but before it, which breaks
|
||||
fontification. Major modes can adjust this variable as a
|
||||
temporarily fix.")
|
||||
affect the fontified range.")
|
||||
|
||||
(defvar-local treesit-font-lock-feature-list nil
|
||||
"A list of lists of feature symbols.
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue