From: Yuan Fu Date: Thu, 8 Dec 2022 00:02:53 +0000 (-0800) Subject: Improve tree-sitter fontification in edge-cases (bug#59738) X-Git-Tag: emacs-29.0.90~1315 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b429e52428851145f8c483acdbb106ba0a0ed2be;p=emacs.git Improve tree-sitter fontification in edge-cases (bug#59738) * lisp/treesit.el (treesit-font-lock-fontify-region): Use treesit--children-covering-range-recurse. --- diff --git a/lisp/treesit.el b/lisp/treesit.el index dbbf7ec18c3..5e87737659e 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -888,6 +888,12 @@ detail.") ;; top-level nodes and query them. This ensures that querying is fast ;; everywhere else, except for the problematic region. ;; +;; Some other time the source file has a top-level node that contains +;; a huge number of children (say, 10k children), querying that node +;; is also very slow, so instead of getting the top-level node, we +;; recursively go down the tree to find nodes that cover the region +;; but are reasonably small. +;; ;; 3. It is possible to capture a node that's completely outside the ;; region between START and END: as long as the whole pattern ;; intersects the region, all the captured nodes in that pattern are @@ -917,8 +923,8 @@ If LOUDLY is non-nil, display some debugging information." ;; If we run into problematic files, use the "fast mode" to ;; try to recover. See comment #2 above for more explanation. (when treesit--font-lock-fast-mode - (setq nodes (treesit--children-covering-range - (car nodes) start end))) + (setq nodes (treesit--children-covering-range-recurse + (car nodes) start end (* 4 jit-lock-chunk-size)))) ;; Query each node. (dolist (sub-node nodes)