tree-sitter-hl-mode, lsp-mode’s Semantic Highlighting, and rust-analyzer
A few weeks ago, I realized I had managed to break my Rust-related lsp-mode configuration in Emacs by switching to the more modern rust-analyzer in the configuration but not having rust-analyzer installed, similarly to the linked entry. Once I had addressed a few related problems, I started to see a warning:
It seems you have configured tree-sitter-hl to activate after lsp-mode. To prevent tree-sitter-hl from overriding lsp-mode's semantic token highlighting, lsp-mode will now disable both semantic highlighting and tree-sitter-hl mode and subsequently re-enable both, starting with tree-sitter-hl-mode. Please adapt your config to prevent unnecessary mode reinitialization in the future.
I tried changing the order of initialization of tree-sitter and lsp-mode, but since it’s all autoloaded via straight.el and use-package, that turned out to be hard to control. Instead, I solved the problem by removing rustic-mode from the list of modes that tree-sitter handles:
(use-package tree-sitter :config (global-tree-sitter-mode) ;; rustic will use rust-analyzer’s semantic highlighting (setf tree-sitter-major-mode-language-alist (cl-remove 'rustic-mode tree-sitter-major-mode-language-alist :key #'car)) ;; other configuration elided :straight t)