fix(tree-sitter): suppress "Can't find grammar" warnings

In Emacs <=30, top-level `treesit-ready-p` calls in various *-ts-mode
packages (like lua-ts-mode or ruby-ts-mode) are commonplace, and they
throw up a warning popup if the grammar isn't available at load time.
This is intrusive. Instead, this forces it to log to *Messages* instead
before falling back to the normal major mode.

Fortunately, these top-level `treesit-ready-p` calls have been removed
in most *-ts-mode packages in 31+, but this still impacts users on <=30
or using third party *-ts-modes that haven't adapted.

However, this doesn't suppress the warning when opening a *-ts-mode.el
file (thanks to the byte-compiler).
This commit is contained in:
Henrik Lissner
2025-08-31 12:30:49 +02:00
parent 86b6ba81ac
commit 94a1fe64a8

View File

@@ -51,7 +51,12 @@
(memq fallback-mode treesit-enabled-modes))
;; Lazily load autoloaded `treesit-language-source-alist'
;; entries.
(let ((fn (symbol-function mode)))
(let ((fn (symbol-function mode))
;; Silence "can't find grammar" warning popups from
;; `treesit-ready-p' calls in Emacs <=30.1. We'll
;; log it to *Messages* instead.
(warning-suppress-types
(cons '(treesit) warning-suppress-types)))
(or (not (autoloadp fn))
(autoload-do-load fn mode)))
;; Only prompt once, and log other times.