Skip to content

Fix nvim-treesitter: highlight regular buffers, not just startup/preview - #2

Open
bkp5190 wants to merge 2 commits into
mainfrom
fm/nvim-treesitter-fix-x5
Open

Fix nvim-treesitter: highlight regular buffers, not just startup/preview#2
bkp5190 wants to merge 2 commits into
mainfrom
fm/nvim-treesitter-fix-x5

Conversation

@bkp5190

@bkp5190 bkp5190 commented Aug 18, 2026

Copy link
Copy Markdown
Owner

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.lua uses main = "nvim-treesitter" + opts = { highlight = ..., indent = ... }, but nvim-treesitter's main branch (pinned in lazy-lock.json) dropped the old configs.setup() API. Its new setup() only reads install_dir — the highlight/indent/ensure_installed opts are silently merged into an internal table and never used. So nothing in this config ever calls vim.treesitter.start() for a normal buffer.

The only reason it looked like it worked: snacks.nvim's quickfile module calls vim.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:

  • Before fix: buffer opened after VimEntervim.treesitter.highlighter.active[buf] is false.
  • After fix: same scenario → true.

Fix

Switch to the main-branch API directly: require("nvim-treesitter").install({...}) for parsers, plus a FileType autocmd that calls vim.treesitter.start() and sets indentexpr for every buffer (highlighting/indent are opt-in on this branch, not automatic).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant