Skip to content

Check if the buffer is valid when trying to attach TS - #2162

Merged
oriori1703 merged 2 commits into
nvim-lua:masterfrom
ollien:fix-ts-install
Sep 9, 2026
Merged

Check if the buffer is valid when trying to attach TS#2162
oriori1703 merged 2 commits into
nvim-lua:masterfrom
ollien:fix-ts-install

Conversation

@ollien

@ollien ollien commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

I found a small race condition in the TS install path, where a closed buffer would pop an error after the buffer isntalled. You can repro by running the below script after deleting your zig queries/parsers from the state directory and running nvim -u repro.lua.

dofile(vim.fn.expand("/path/to/kickstart.nvim/init.lua"))

vim.fn.mkdir("/tmp/ts-repro", "p")
vim.fn.writefile({ "const x = 1;" }, "/tmp/ts-repro/sample.zig")

vim.schedule(function()
	vim.cmd("edit /tmp/ts-repro/sample.zig")
	vim.cmd("bwipeout!")
end)

You should expect to see

vim.schedule callback: /opt/nvim/share/nvim/runtime/lua/vim/treesitter.lua:443:
 Invalid buffer id: 1   

This PR fixes that bug by checking if the buffer is still valid before attempting to attach TS.

@oriori1703
oriori1703 merged commit 748f67f into nvim-lua:master Sep 9, 2026
1 check passed
@oriori1703

Copy link
Copy Markdown
Collaborator

Thanks for the great reproduction and fix :)

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.

2 participants