mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-03 14:04:34 +02:00
perf(treesitter): better way of loading treesitter-textobjects
This commit is contained in:
parent
8281bd2f63
commit
09fafb946a
1 changed files with 22 additions and 16 deletions
|
@ -1,32 +1,23 @@
|
||||||
|
local load_textobjects = false
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
version = false, -- last release is way too old and doesn't work on Windows
|
version = false, -- last release is way too old and doesn't work on Windows
|
||||||
build = ":TSUpdate",
|
build = ":TSUpdate",
|
||||||
event = { "BufReadPost", "BufNewFile" },
|
event = { "BufReadPost", "BufNewFile" },
|
||||||
cmd = { "TSUpdateSync" },
|
|
||||||
dependencies = {
|
dependencies = {
|
||||||
{
|
{
|
||||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||||
init = function()
|
init = function()
|
||||||
-- PERF: no need to load the plugin, if we only need its queries for mini.ai
|
-- disable rtp plugin, as we only need its queries for mini.ai
|
||||||
local plugin = require("lazy.core.config").spec.plugins["nvim-treesitter"]
|
-- In case other textobject modules are enabled, we will load them
|
||||||
local opts = require("lazy.core.plugin").values(plugin, "opts", false)
|
-- once nvim-treesitter is loaded
|
||||||
local enabled = false
|
require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects")
|
||||||
if opts.textobjects then
|
load_textobjects = true
|
||||||
for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do
|
|
||||||
if opts.textobjects[mod] and 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,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
cmd = { "TSUpdateSync" },
|
||||||
keys = {
|
keys = {
|
||||||
{ "<c-space>", desc = "Increment selection" },
|
{ "<c-space>", desc = "Increment selection" },
|
||||||
{ "<bs>", desc = "Decrement selection", mode = "x" },
|
{ "<bs>", desc = "Decrement selection", mode = "x" },
|
||||||
|
@ -79,6 +70,21 @@ return {
|
||||||
end, opts.ensure_installed)
|
end, opts.ensure_installed)
|
||||||
end
|
end
|
||||||
require("nvim-treesitter.configs").setup(opts)
|
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,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue