]> git.rmz.io Git - dotfiles.git/commitdiff
nvim: tidy treesitter plugins
authorSamir Benmendil <me@rmz.io>
Sat, 15 Feb 2025 19:27:10 +0000 (19:27 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 2 Mar 2025 16:05:27 +0000 (16:05 +0000)
- just get nvim-treesitter-textobjects as a dependency
  - merge its config into nvim-treesitter

nvim/lua/plugins/treesitter.lua

index cb5fa7ec36640c9da4e73a67d6b1f05fcfae0504..96e8c1a415a60bf5b328e7c9f55063ea29efbab8 100644 (file)
@@ -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<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