Validate font-lock rules when setting up tree-sitter major mode
When tree-sitter grammar make breaking changes, major modes
breaks completely: no highlighting is shown. This new function
will run in treesit-major-mode-setup, validate each
font-lock features, and disable the ones that are not compatible
with the new grammar, so that the rest of the features still
work. It also displays a warning explaining the situation,
which looks like this:
Warning (treesit-font-lock-rules-mismatch): 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.
This error can be fixed by either downgrading the
grammar (tree-sitter-c) on your system, or upgrading the
major mode package. The following are the temporarily
disabled features:
- `preprocessor' for c.
* lisp/treesit.el (treesit-validate-font-lock-rules): New function.
(treesit-major-mode-setup): Validate font-lock rules.
(cherry picked from commit
ed9eaaa9964f46ef5f9a9c084a1cb8f1ae1926a3)