fix(treesitter): refactored treesitter code and fixed nvim-treesitter-textobjects

This commit is contained in:
Folke Lemaitre 2024-05-18 21:37:25 +02:00
parent 4bc9389bb5
commit fe552853f5
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -74,27 +74,23 @@ return {
---@param opts TSConfig
config = function(_, opts)
if type(opts.ensure_installed) == "table" then
---@type table<string, boolean>
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<string,fun(...)>