mirror of
https://github.com/neovim/neovim.git
synced 2026-07-10 03:19:44 +00:00
Merge pull request #22023 from neovim/fix-syntax
* fix(treesitter): properly restore `'syntax'` (#21358) * fix(treesitter): really restore syntax - also unset b:ts_highlight on stop() Fixes: #21836
This commit is contained in:
@@ -326,12 +326,8 @@ end
|
||||
---@param lang (string|nil) Language of the parser (default: buffer filetype)
|
||||
function M.start(bufnr, lang)
|
||||
bufnr = bufnr or a.nvim_get_current_buf()
|
||||
|
||||
local parser = M.get_parser(bufnr, lang)
|
||||
|
||||
M.highlighter.new(parser)
|
||||
|
||||
vim.b[bufnr].ts_highlight = true
|
||||
end
|
||||
|
||||
--- Stops treesitter highlighting for a buffer
|
||||
@@ -343,8 +339,6 @@ function M.stop(bufnr)
|
||||
if M.highlighter.active[bufnr] then
|
||||
M.highlighter.active[bufnr]:destroy()
|
||||
end
|
||||
|
||||
vim.bo[bufnr].syntax = 'on'
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -89,6 +89,7 @@ function TSHighlighter.new(tree, opts)
|
||||
end
|
||||
|
||||
vim.bo[self.bufnr].syntax = ''
|
||||
vim.b[self.bufnr].ts_highlight = true
|
||||
|
||||
TSHighlighter.active[self.bufnr] = self
|
||||
|
||||
@@ -114,6 +115,14 @@ function TSHighlighter:destroy()
|
||||
if TSHighlighter.active[self.bufnr] then
|
||||
TSHighlighter.active[self.bufnr] = nil
|
||||
end
|
||||
|
||||
if vim.api.nvim_buf_is_loaded(self.bufnr) then
|
||||
vim.bo[self.bufnr].spelloptions = self.orig_spelloptions
|
||||
vim.b[self.bufnr].ts_highlight = nil
|
||||
if vim.g.syntax_on == 1 then
|
||||
a.nvim_exec_autocmds('FileType', { group = 'syntaxset', buffer = self.bufnr })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
|
||||
Reference in New Issue
Block a user