From b5c290cfbd1da4a0c640d7cbf92741e5d8eb64b8 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 30 Oct 2025 18:05:10 -0700 Subject: [PATCH] Revert "Use cached compiled tree-sitter queries for range settings" This reverts commit e28ec7627148e523e215ee672b3dda40f1a6ad44. * lisp/treesit.el (treesit-range-rules): Use treesit-query-compile. --- lisp/treesit.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 680b1fc4cee..2f83b698cf3 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -757,7 +757,22 @@ that encompasses the region between START and END." (when (null host) (signal 'treesit-error (list "Value of :host option cannot be omitted"))) (when (treesit-available-p) - (push (list (treesit--compile-query-with-cache host query) + ;; Don't replace this with + ;; `treesit--compile-query-with-cache'. + ;; `treesit-query-compile' is lazy and don't actually + ;; load the grammar until the query is + ;; used. `treesit--compile-query-with-cache' compiles + ;; eagerly so it's not safe to use for this function + ;; which might be called when loading a package. To + ;; do it properly like font-lock, we need to not + ;; compile the queries here, and compile them with + ;; `treesit--compile-query-with-cache' when major + ;; mode is enabled. Let's just keep things simple + ;; and keep range rules as-is. Because for range + ;; rules, the queries generally don't need to + ;; computed dynamically, and queries are simple and + ;; few, so recompiling isn't as much of a problem. + (push (list (treesit-query-compile host query) embed local offset range-fn) result))) (setq host nil embed nil offset nil local nil range-fn nil))))