From: Samir Benmendil Date: Sat, 15 Feb 2025 19:27:10 +0000 (+0000) Subject: nvim: tidy treesitter plugins X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/8e1fb59140f7d75ea63197c5f9615fc3dca60584 nvim: tidy treesitter plugins - just get nvim-treesitter-textobjects as a dependency - merge its config into nvim-treesitter --- diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index cb5fa7e..96e8c1a 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -1,8 +1,6 @@ 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 @@ -73,40 +71,27 @@ return { }, ---@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 - 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 - 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 + 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