emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter 9fbbb23552 2/2: Fix incorrect tree-sitter fontificat


From: Yuan Fu
Subject: feature/tree-sitter 9fbbb23552 2/2: Fix incorrect tree-sitter fontification
Date: Sat, 5 Nov 2022 22:01:15 -0400 (EDT)

branch: feature/tree-sitter
commit 9fbbb2355298f75e8fd09b35306e843ce45b9e25
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Fix incorrect tree-sitter fontification
    
    * lisp/treesit.el (treesit-font-lock-fontify-region): If the captured
    node is outside of the region between START and END, don't fontify it.
    Wrap fontification code in a when form.
---
 lisp/treesit.el | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 7233ce7f18..84be69d8b7 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -846,23 +846,30 @@ If LOUDLY is non-nil, display some debugging information."
                      (node (cdr capture))
                      (node-start (treesit-node-start node))
                      (node-end (treesit-node-end node)))
-                (cond
-                 ((eq face 'contextual)
-                  (treesit-font-lock-contextual-post-process
-                   node start end
-                   (or loudly treesit--font-lock-verbose)))
-                 ((facep face)
-                  (treesit-fontify-with-override
-                   (max node-start start) (min node-end end)
-                   face override))
-                 ((functionp face)
-                  (funcall face node override start end)))
-                ;; Don't raise an error if FACE is neither a face nor
-                ;; a function.  This is to allow intermediate capture
-                ;; names used for #match and #eq.
-                (when (or loudly treesit--font-lock-verbose)
-                  (message "Fontifying text from %d to %d, Face: %s, Node: %s"
-                           start end face (treesit-node-type node))))))))))
+                ;; Turns out it is possible to capture a node that's
+                ;; completely outside the region between START and
+                ;; END.  If the node is outside of that region, (max
+                ;; node-start start) and friends return bad values.
+                (when (and (< start node-end)
+                           (< node-start end))
+                  (cond
+                   ((eq face 'contextual)
+                    (treesit-font-lock-contextual-post-process
+                     node start end
+                     (or loudly treesit--font-lock-verbose)))
+                   ((facep face)
+                    (treesit-fontify-with-override
+                     (max node-start start) (min node-end end)
+                     face override))
+                   ((functionp face)
+                    (funcall face node override start end)))
+                  ;; Don't raise an error if FACE is neither a face nor
+                  ;; a function.  This is to allow intermediate capture
+                  ;; names used for #match and #eq.
+                  (when (or loudly treesit--font-lock-verbose)
+                    (message "Fontifying text from %d to %d, Face: %s, Node: 
%s"
+                             (max node-start start) (min node-end end)
+                             face (treesit-node-type node)))))))))))
   `(jit-lock-bounds ,start . ,end))
 
 ;;; Indent



reply via email to

[Prev in Thread] Current Thread [Next in Thread]