Fix nvim-treesitter: highlight regular buffers, not just startup/preview - #2
Open
bkp5190 wants to merge 2 commits into
Open
Fix nvim-treesitter: highlight regular buffers, not just startup/preview#2bkp5190 wants to merge 2 commits into
bkp5190 wants to merge 2 commits into
Conversation
nvim-treesitter's main branch (pinned in lazy-lock.json) removed the
old require("nvim-treesitter.configs").setup({...}) API, so the
main-based opts = {highlight=..., indent=...} spec was silently a
no-op (unknown keys ignored by the new setup(), which only accepts
install_dir). Switch to the new API: require("nvim-treesitter").install()
for parsers, plus a FileType autocmd to start highlighting and set
indentexpr, since those are no longer auto-enabled by configs.setup.
Verified via headless nvim against this config: no errors on startup,
and vim.treesitter.highlighter.active is true for both a Python and a
Lua buffer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Regular buffers opened during a running session (via
:e, a picker selection, etc.) got no treesitter highlighting, even though the config looked fine and the file at Vim startup / picker previews highlighted correctly.Root cause
The current
treesitter.luausesmain = "nvim-treesitter"+opts = { highlight = ..., indent = ... }, but nvim-treesitter'smainbranch (pinned in lazy-lock.json) dropped the oldconfigs.setup()API. Its newsetup()only readsinstall_dir— thehighlight/indent/ensure_installedopts are silently merged into an internal table and never used. So nothing in this config ever callsvim.treesitter.start()for a normal buffer.The only reason it looked like it worked:
snacks.nvim'squickfilemodule callsvim.treesitter.start()itself for the buffer open at Vim startup, and its picker preview does the same for preview panes — both bypass this plugin's config entirely. Any buffer opened afterwards (the common case) got no highlighting.Verified with headless nvim against the real live config/data dirs:
VimEnter→vim.treesitter.highlighter.active[buf]isfalse.true.Fix
Switch to the
main-branch API directly:require("nvim-treesitter").install({...})for parsers, plus aFileTypeautocmd that callsvim.treesitter.start()and setsindentexprfor every buffer (highlighting/indent are opt-in on this branch, not automatic).