From fe552853f5c065df2d79092c0cbac6745f8ea8fc Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 18 May 2024 21:37:25 +0200 Subject: [PATCH] fix(treesitter): refactored treesitter code and fixed nvim-treesitter-textobjects --- lua/lazyvim/plugins/treesitter.lua | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index 19aef89b..7d3b5e89 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -74,27 +74,23 @@ return { ---@param opts TSConfig config = function(_, opts) if type(opts.ensure_installed) == "table" then - ---@type table - local added = {} - opts.ensure_installed = vim.tbl_filter(function(lang) - if added[lang] then - return false - end - added[lang] = true - return true - end, opts.ensure_installed) + opts.ensure_installed = LazyVim.dedup(opts.ensure_installed) end require("nvim-treesitter.configs").setup(opts) - vim.schedule(function() - require("lazy").load({ plugins = { "nvim-treesitter-textobjects" } }) - end) end, }, { "nvim-treesitter/nvim-treesitter-textobjects", - lazy = true, + event = "VeryLazy", + enabled = true, config = function() + -- If treesitter is already loaded, we need to run config again for textobjects + if LazyVim.is_loaded("nvim-treesitter") then + local opts = LazyVim.opts("nvim-treesitter") + require("nvim-treesitter.configs").setup({ textobjects = opts.textobjects }) + end + -- When in diff mode, we want to use the default -- vim text objects c & C instead of the treesitter ones. local move = require("nvim-treesitter.textobjects.move") ---@type table