diff options
| author | Sean Dewar <6256228+seandewar@users.noreply.github.com> | 2025-08-19 16:14:10 +0100 |
|---|---|---|
| committer | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2025-08-19 19:52:41 +0000 |
| commit | fa64f2d09bab17cfebcdf0533652aaf331cec2e9 (patch) | |
| tree | 9cb15cdff66bbd50c9d4e137be487636780612e0 /runtime | |
| parent | 3ab06d5188bc7ccd993e4577196dca03bebb0129 (diff) | |
fix(treesitter): run FileType autocmds in the context of `<abuf>`
Problem: many FileType autocommands assume curbuf is the same as the target
buffer; this can cause &syntax to be restored for the wrong buffer in some cases
when TSHighlighter:destroy is called.
Solution: run nvim_exec_autocmds in the context of the target buffer via
nvim_buf_call.
(cherry picked from commit 3ec63cdab848f903d5e46245b7b2acbf7d5cc829)
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 766f5f5416..11c9787669 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -182,10 +182,13 @@ function TSHighlighter:destroy() vim.b[self.bufnr].ts_highlight = nil api.nvim_buf_clear_namespace(self.bufnr, ns, 0, -1) if vim.g.syntax_on == 1 then - api.nvim_exec_autocmds( - 'FileType', - { group = 'syntaxset', buffer = self.bufnr, modeline = false } - ) + -- FileType autocmds commonly assume curbuf is the target buffer, so nvim_buf_call. + api.nvim_buf_call(self.bufnr, function() + api.nvim_exec_autocmds( + 'FileType', + { group = 'syntaxset', buffer = self.bufnr, modeline = false } + ) + end) end end end |
