Function: treesit-validate-and-compile-font-lock-rules
treesit-validate-and-compile-font-lock-rules is a byte-compiled
function defined in treesit.el.gz.
Signature
(treesit-validate-and-compile-font-lock-rules SETTINGS)
Documentation
Validate and resolve font-lock rules in SETTINGS before major mode starts.
For each enabled setting, if query isn't compiled, compile it and replace the query In-PLACE.
If the tree-sitter grammar currently installed on the system is incompatible with the major mode's font-lock rules, this procedure will detect the problematic rule, disable it temporarily, and notify the user.
Source Code
;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-validate-and-compile-font-lock-rules (settings)
"Validate and resolve font-lock rules in SETTINGS before major mode starts.
For each enabled setting, if query isn't compiled, compile it and
replace the query In-PLACE.
If the tree-sitter grammar currently installed on the system is
incompatible with the major mode's font-lock rules, this procedure will
detect the problematic rule, disable it temporarily, and notify the
user."
(let ((faulty-features ()))
(dolist (setting settings)
(let* ((query (treesit-font-lock-setting-query setting))
(lang (treesit-font-lock-setting-language setting))
(enabled (treesit-font-lock-setting-enable setting)))
(when enabled
(condition-case nil
(let ((compiled (treesit--compile-query-with-cache lang query)))
;; Here we're modifying SETTINGS in-place.
(setcar setting compiled))
(treesit-query-error
(push (cons (treesit-font-lock-setting-feature setting)
lang)
faulty-features))))))
(when faulty-features
(treesit-font-lock-recompute-features
nil (mapcar #'car faulty-features))
(let* ((languages
(string-join
(delete-dups (mapcar (lambda (feat)
(format "tree-sitter-%s" (cdr feat)))
faulty-features))
", "))
(features (string-join
(mapcar
(lambda (feat)
(format "- `%s' for %s"
(car feat) (cdr feat)))
faulty-features)
",\n")))
(display-warning
'treesit-font-lock-rules-mismatch
(format "Emacs cannot compile every font-lock rules because a mismatch between the grammar and the rules. This is most likely due to a mismatch between the font-lock rules defined by the major mode and the tree-sitter grammar.\n\nThis error can be fixed by either downgrading the grammar (%s) on your system, or upgrading the major mode package. The following are the temporarily disabled features:\n\n%s."
languages features))))))