diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 67e37b9c..f9ef9bee 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -151,15 +151,7 @@ return { -- { "i", mode = { "x", "o" } }, -- }, event = "VeryLazy", - dependencies = { - { - "nvim-treesitter/nvim-treesitter-textobjects", - init = function() - -- no need to load the plugin, since we only need its queries - require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects") - end, - }, - }, + dependencies = { "nvim-treesitter-textobjects" }, opts = function() local ai = require("mini.ai") return { diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index 96920f55..7175c8b9 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -4,6 +4,28 @@ return { version = false, -- last release is way too old and doesn't work on Windows build = ":TSUpdate", event = { "BufReadPost", "BufNewFile" }, + dependencies = { + { + "nvim-treesitter/nvim-treesitter-textobjects", + init = function() + -- PERF: no need to load the plugin, if we only need its queries for mini.ai + local plugin = require("lazy.core.config").spec.plugins["nvim-treesitter"] + local opts = require("lazy.core.plugin").values(plugin, "opts", false) + local enabled = false + if opts.textobjects then + for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do + if opts.textobjects[mod].enable then + enabled = true + break + end + end + end + if not enabled then + require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects") + end + end, + }, + }, keys = { { "", desc = "Increment selection" }, { "", desc = "Schrink selection", mode = "x" },