diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 7a710e9..0ac5198 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,3 +1,16 @@ +-- This hook checks for a treesitter update, verifies that the plugin +-- is active and runs TSUpdate +-- !! It needs to be defined before vim.pack.add to work +vim.api.nvim_create_autocmd('PackChanged', { + callback = function(ev) + local name, kind = ev.data.spec.name, ev.data.kind + if name == 'nvim-treesitter' and kind == 'update' then + if not ev.data.active then vim.cmd.packadd('nvim-treesitter') end + vim.cmd('TSUpdate') + end + end +}) + vim.pack.add({ { src = 'https://github.com/nvim-treesitter/nvim-treesitter', name = 'treesitter', branch = 'main' }, { src = 'https://github.com/nvim-treesitter/nvim-treesitter-context', name = 'treesitter-context' },