mirror of
https://github.com/neovim/neovim.git
synced 2026-01-06 21:37:43 +00:00
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 3ec63cdab8)
This commit is contained in:
committed by
github-actions[bot]
parent
3ab06d5188
commit
fa64f2d09b
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user