From b429e52428851145f8c483acdbb106ba0a0ed2be Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Wed, 7 Dec 2022 16:02:53 -0800 Subject: [PATCH] Improve tree-sitter fontification in edge-cases (bug#59738) * lisp/treesit.el (treesit-font-lock-fontify-region): Use treesit--children-covering-range-recurse. --- lisp/treesit.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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) -- 2.39.2