From 0e66ef83934eb62ee2237e331dcbc0a22b809aae Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 4 Oct 2023 00:12:32 +0200 Subject: [PATCH] feat(treesitter): added ]f, [f, ]F, [F, ]c, ]C, [c, [C for treesitter-textobjects --- lua/lazyvim/plugins/coding.lua | 1 - lua/lazyvim/plugins/treesitter.lua | 32 +++++++++--------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 7250638d..0e01d277 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -179,7 +179,6 @@ return { -- { "i", mode = { "x", "o" } }, -- }, event = "VeryLazy", - 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 b84d01a7..0b9b6895 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -1,4 +1,3 @@ -local load_textobjects = false return { -- Treesitter is a new parser generator tool that we can -- use in Neovim to power faster and more accurate @@ -11,13 +10,6 @@ return { dependencies = { { "nvim-treesitter/nvim-treesitter-textobjects", - init = function() - -- disable rtp plugin, as we only need its queries for mini.ai - -- In case other textobject modules are enabled, we will load them - -- once nvim-treesitter is loaded - require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects") - load_textobjects = true - end, }, }, cmd = { "TSUpdateSync" }, @@ -59,6 +51,15 @@ return { node_decremental = "", }, }, + textobjects = { + move = { + enable = true, + goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" }, + goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer" }, + goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" }, + goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer" }, + }, + }, }, ---@param opts TSConfig config = function(_, opts) @@ -74,21 +75,6 @@ return { end, opts.ensure_installed) end require("nvim-treesitter.configs").setup(opts) - - if load_textobjects then - -- PERF: no need to load the plugin, if we only need its queries for mini.ai - if opts.textobjects then - for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do - if opts.textobjects[mod] and opts.textobjects[mod].enable then - local Loader = require("lazy.core.loader") - Loader.disabled_rtp_plugins["nvim-treesitter-textobjects"] = nil - local plugin = require("lazy.core.config").plugins["nvim-treesitter-textobjects"] - require("lazy.core.loader").source_runtime(plugin.dir, "plugin") - break - end - end - end - end end, }, }