mirror of
https://github.com/neovim/neovim
synced 2025-07-19 10:41:48 +00:00
fix(treesitter): ensure syntaxset augroup exists (#29542)
Problem:
Error when calling vim.treesitter.start() and vim.treesitter.stop() in
init.lua.
Solution:
Ensure syntaxset augroup exists after loading synload.vim.
(cherry picked from commit d413038b4f
)
This commit is contained in:
committed by
github-actions[bot]
parent
803cc08c17
commit
356ddb1305
@ -139,8 +139,11 @@ function TSHighlighter.new(tree, opts)
|
|||||||
-- but use synload.vim rather than syntax.vim to not enable
|
-- but use synload.vim rather than syntax.vim to not enable
|
||||||
-- syntax FileType autocmds. Later on we should integrate with the
|
-- syntax FileType autocmds. Later on we should integrate with the
|
||||||
-- `:syntax` and `set syntax=...` machinery properly.
|
-- `:syntax` and `set syntax=...` machinery properly.
|
||||||
|
-- Still need to ensure that syntaxset augroup exists, so that calling :destroy()
|
||||||
|
-- immediately afterwards will not error.
|
||||||
if vim.g.syntax_on ~= 1 then
|
if vim.g.syntax_on ~= 1 then
|
||||||
vim.cmd.runtime({ 'syntax/synload.vim', bang = true })
|
vim.cmd.runtime({ 'syntax/synload.vim', bang = true })
|
||||||
|
vim.api.nvim_create_augroup('syntaxset', { clear = false })
|
||||||
end
|
end
|
||||||
|
|
||||||
api.nvim_buf_call(self.bufnr, function()
|
api.nvim_buf_call(self.bufnr, function()
|
||||||
|
@ -10,8 +10,6 @@ local command = n.command
|
|||||||
local api = n.api
|
local api = n.api
|
||||||
local eq = t.eq
|
local eq = t.eq
|
||||||
|
|
||||||
before_each(clear)
|
|
||||||
|
|
||||||
local hl_query_c = [[
|
local hl_query_c = [[
|
||||||
(ERROR) @error
|
(ERROR) @error
|
||||||
|
|
||||||
@ -120,6 +118,7 @@ describe('treesitter highlighting (C)', function()
|
|||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
clear()
|
||||||
screen = Screen.new(65, 18)
|
screen = Screen.new(65, 18)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
screen:set_default_attr_ids {
|
screen:set_default_attr_ids {
|
||||||
@ -800,6 +799,7 @@ describe('treesitter highlighting (lua)', function()
|
|||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
clear()
|
||||||
screen = Screen.new(65, 18)
|
screen = Screen.new(65, 18)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
screen:set_default_attr_ids {
|
screen:set_default_attr_ids {
|
||||||
@ -838,6 +838,7 @@ describe('treesitter highlighting (help)', function()
|
|||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
clear()
|
||||||
screen = Screen.new(40, 6)
|
screen = Screen.new(40, 6)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
screen:set_default_attr_ids {
|
screen:set_default_attr_ids {
|
||||||
@ -939,6 +940,7 @@ describe('treesitter highlighting (nested injections)', function()
|
|||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
clear()
|
||||||
screen = Screen.new(80, 7)
|
screen = Screen.new(80, 7)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
screen:set_default_attr_ids {
|
screen:set_default_attr_ids {
|
||||||
@ -1006,6 +1008,7 @@ describe('treesitter highlighting (markdown)', function()
|
|||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
clear()
|
||||||
screen = Screen.new(40, 6)
|
screen = Screen.new(40, 6)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
exec_lua([[
|
exec_lua([[
|
||||||
@ -1053,3 +1056,19 @@ printf('Hello World!');
|
|||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('starting and stopping treesitter highlight in init.lua works #29541', function()
|
||||||
|
t.write_file(
|
||||||
|
'Xinit.lua',
|
||||||
|
[[
|
||||||
|
vim.bo.ft = 'c'
|
||||||
|
vim.treesitter.start()
|
||||||
|
vim.treesitter.stop()
|
||||||
|
]]
|
||||||
|
)
|
||||||
|
finally(function()
|
||||||
|
os.remove('Xinit.lua')
|
||||||
|
end)
|
||||||
|
clear({ args = { '-u', 'Xinit.lua' } })
|
||||||
|
eq('', api.nvim_get_vvar('errmsg'))
|
||||||
|
end)
|
||||||
|
Reference in New Issue
Block a user