mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
decouple mini.ai and which-key.nvim
This commit is contained in:
parent
abea2807ce
commit
867f33a5a6
2 changed files with 40 additions and 30 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
local Util = require("lazyvim.util")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
-- snippets
|
-- snippets
|
||||||
|
|
@ -147,34 +149,13 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
-- better text-objects
|
-- add mini.ai descriptions to which-key.nvim
|
||||||
{
|
{
|
||||||
"echasnovski/mini.ai",
|
"folke/which-key.nvim",
|
||||||
-- keys = {
|
optional = true,
|
||||||
-- { "a", mode = { "x", "o" } },
|
opts = function(_, opts)
|
||||||
-- { "i", mode = { "x", "o" } },
|
local function mini_ai_to_which_key()
|
||||||
-- },
|
-- register all text objects with which-key
|
||||||
event = "VeryLazy",
|
|
||||||
dependencies = { "nvim-treesitter-textobjects" },
|
|
||||||
opts = function()
|
|
||||||
local ai = require("mini.ai")
|
|
||||||
return {
|
|
||||||
n_lines = 500,
|
|
||||||
custom_textobjects = {
|
|
||||||
o = ai.gen_spec.treesitter({
|
|
||||||
a = { "@block.outer", "@conditional.outer", "@loop.outer" },
|
|
||||||
i = { "@block.inner", "@conditional.inner", "@loop.inner" },
|
|
||||||
}, {}),
|
|
||||||
f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}),
|
|
||||||
c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }, {}),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
config = function(_, opts)
|
|
||||||
require("mini.ai").setup(opts)
|
|
||||||
-- register all text objects with which-key
|
|
||||||
if require("lazyvim.util").has("which-key.nvim") then
|
|
||||||
---@type table<string, string|table>
|
|
||||||
local i = {
|
local i = {
|
||||||
[" "] = "Whitespace",
|
[" "] = "Whitespace",
|
||||||
['"'] = 'Balanced "',
|
['"'] = 'Balanced "',
|
||||||
|
|
@ -209,12 +190,38 @@ return {
|
||||||
i[key] = vim.tbl_extend("force", { name = "Inside " .. name .. " textobject" }, ic)
|
i[key] = vim.tbl_extend("force", { name = "Inside " .. name .. " textobject" }, ic)
|
||||||
a[key] = vim.tbl_extend("force", { name = "Around " .. name .. " textobject" }, ac)
|
a[key] = vim.tbl_extend("force", { name = "Around " .. name .. " textobject" }, ac)
|
||||||
end
|
end
|
||||||
require("which-key").register({
|
return {
|
||||||
mode = { "o", "x" },
|
mode = { "o", "x" },
|
||||||
i = i,
|
i = i,
|
||||||
a = a,
|
a = a,
|
||||||
})
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Util.has("mini.ai") then
|
||||||
|
opts.mini_ai = mini_ai_to_which_key()
|
||||||
|
end
|
||||||
|
return opts
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- better text-objects
|
||||||
|
{
|
||||||
|
"echasnovski/mini.ai",
|
||||||
|
event = "VeryLazy",
|
||||||
|
dependencies = { "nvim-treesitter-textobjects" },
|
||||||
|
opts = function()
|
||||||
|
local ai = require("mini.ai")
|
||||||
|
return {
|
||||||
|
n_lines = 500,
|
||||||
|
custom_textobjects = {
|
||||||
|
o = ai.gen_spec.treesitter({
|
||||||
|
a = { "@block.outer", "@conditional.outer", "@loop.outer" },
|
||||||
|
i = { "@block.inner", "@conditional.inner", "@loop.inner" },
|
||||||
|
}, {}),
|
||||||
|
f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }, {}),
|
||||||
|
c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }, {}),
|
||||||
|
},
|
||||||
|
}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,6 @@ return {
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- which-key
|
|
||||||
{
|
{
|
||||||
"folke/which-key.nvim",
|
"folke/which-key.nvim",
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
|
|
@ -268,11 +267,15 @@ return {
|
||||||
["<leader>w"] = { name = "+windows" },
|
["<leader>w"] = { name = "+windows" },
|
||||||
["<leader>x"] = { name = "+diagnostics/quickfix" },
|
["<leader>x"] = { name = "+diagnostics/quickfix" },
|
||||||
},
|
},
|
||||||
|
mini_ai = nil, -- descriptions for mini.ai when enabled
|
||||||
},
|
},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local wk = require("which-key")
|
local wk = require("which-key")
|
||||||
wk.setup(opts)
|
wk.setup(opts)
|
||||||
wk.register(opts.defaults)
|
wk.register(opts.defaults)
|
||||||
|
if opts.mini_ai then
|
||||||
|
wk.register(opts.mini_ai)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue