return {
{ "nvim-treesitter/nvim-treesitter",
- -- Treesitter is a new parser generator tool that we can
- -- use in Neovim to power faster and more accurate
- -- syntax highlighting.
+ dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" },
build = ":TSUpdate",
event = { "LazyFile", "VeryLazy" },
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
},
---@param opts TSConfig
config = function(_, opts)
- if type(opts.ensure_installed) == "table" then
- opts.ensure_installed = rmz.dedup(opts.ensure_installed)
- end
- require("nvim-treesitter.configs").setup(opts)
- end,
- },
+ -- make sure extra langs are not duplicated
+ opts.ensure_installed = rmz.dedup(opts.ensure_installed)
- { "nvim-treesitter/nvim-treesitter-textobjects",
- 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
+ local configs = require("nvim-treesitter.configs")
+ configs.setup(opts)
-- 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(...)>
- local configs = require("nvim-treesitter.configs")
for name, fn in pairs(move) do
if name:find("goto") == 1 then
move[name] = function(q, ...)
- if vim.wo.diff then
- local config = configs.get_module("textobjects.move")[name] ---@type table<string,string>
- for key, query in pairs(config or {}) do
- if q == query and key:find("[%]%[][cC]") then
- vim.cmd("normal! " .. key)
- return
- end
+ if not vim.wo.diff then return fn(q, ...) end
+
+ local config = configs.get_module("textobjects.move")[name] ---@type table<string,string>
+ for key, query in pairs(config or {}) do
+ if q == query and key:find("[%]%[][cC]") then
+ vim.cmd("normal! " .. key)
+ return
end
end
- return fn(q, ...)
end
end
end