Skip to content

Commit

Permalink
feat!: which-key v3 integration and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Allaman committed Jul 13, 2024
1 parent a37ad5a commit 6e441f3
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 139 deletions.
7 changes: 7 additions & 0 deletions after/ftplugin/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ local vo = vim.opt_local
vo.tabstop = 4
vo.shiftwidth = 4
vo.softtabstop = 4

local wk = require("which-key")
wk.add({
{ "<leader>c", "", desc = "+Coding" },
{ "<leader>cl", "<cmd>lua print('TODO')<cr>", desc = "Todo" },
{ "<leader>cc", "<cmd>lua print('TODO')<cr>", desc = "Todo2" },
})
36 changes: 18 additions & 18 deletions after/ftplugin/lua.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
local wk = require("which-key")
wk.register({
c = {
name = "Coding",
r = {
function()
require("luapad.run").run()
end,
"Run buffer content",
},
l = {
function()
require("luapad").init()
end,
"Luapad",
},
t = { "<cmd>lua MiniTest.run_file()<cr>", "MiniTest for current file" },
s = { "<cmd>lua MiniTest.run()<cr>", "Run MiniTest suite" },
wk.add({
{ "<leader>c", "", desc = "+Coding" },
{
"<leader>cr",
function()
require("luapad.run").run()
end,
desc = "Run buffer content",
},
}, { prefix = "<leader>", mode = "n" })
{
"<leader>cl",
function()
require("luapad").init()
end,
desc = "Luapad",
},
{ "<leader>ct", "<cmd>lua MiniTest.run_file()<cr>", desc = "MiniTest for current file" },
{ "<leader>cs", "<cmd>lua MiniTest.run()<cr>", desc = "Run MiniTest suite" },
})
5 changes: 5 additions & 0 deletions after/ftplugin/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ local vo = vim.opt_local
vo.tabstop = 4
vo.shiftwidth = 4
vo.softtabstop = 4

local wk = require("which-key")
wk.add({
{ "<leader>dp", "", desc = "+Python" },
})
13 changes: 1 addition & 12 deletions lua/core/plugins/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ end

-- stylua: ignore
local default_config = {
groups = {
["<leader>d"] = { "Debug" },
["<leader>dp"] = { "Python" },
},
dap = {
keys = {
{"<leader>d", "", desc = "+Debug" },
{ "<leader>db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
{ "<leader>dc", function() require("dap").run_to_cursor() end, desc = "Continue" },
{ "<leader>di", function() require("dap").step_into() end, desc = "Step Into" },
Expand Down Expand Up @@ -131,12 +128,4 @@ return {
},
},
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = config.groups,
},
},
}
14 changes: 4 additions & 10 deletions lua/core/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ local user_config = vim.g.config.plugins.gitsigns or {}

local default_config = {
enabled = true,
keys = {
{ "<leader>g", "", desc = "+Git" },
},
opts = {
on_attach = function(buffer)
local gs = package.loaded.gitsigns
Expand Down Expand Up @@ -35,18 +38,9 @@ return {
"nvim-lua/plenary.nvim",
},
opts = config.opts,
keys = config.keys,
config = function(_, opts)
require("gitsigns").setup(opts)
end,
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = {
["<leader>g"] = { name = "Git" },
},
},
},
}
12 changes: 1 addition & 11 deletions lua/core/plugins/gp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ local user_config = vim.g.config.plugins.gp or {}

local default_config = {
enabled = false,
groups = {
["<leader>i"] = { name = "AI" },
},
keys = {
{ "<leader>i", "", desc = "+AI" },
{ "<leader>iv", "<cmd>GpChatNew vsplit<cr>", desc = "New Chat (vsplit)" },
{ "<leader>it", "<cmd>GpChatToggle<cr>", desc = "Toggle last chat" },
{ "<leader>if", "<cmd>GpChatFinder<cr>", desc = "Find chat" },
Expand Down Expand Up @@ -64,12 +62,4 @@ return {
config.config_function(opts)
end,
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = config.groups,
},
},
}
7 changes: 0 additions & 7 deletions lua/core/plugins/lsp/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ M._keys = {
function M.on_attach(client, buffer)
local Keys = require("lazy.core.handler.keys")
local keymaps = {}
local wk = require("which-key")

wk.register({
l = {
w = { "Workspaces" },
},
}, { prefix = "<leader>", mode = "n" })

for _, value in ipairs(M._keys) do
local keys = Keys.parse(value)
Expand Down
14 changes: 2 additions & 12 deletions lua/core/plugins/mini.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local utils = require("utils.functions")
return {

return {
{
"echasnovski/mini.comment",
-- built-in in Neovim 10
Expand All @@ -26,17 +26,7 @@ return {
":normal saiW`<Esc>",
{ desc = "Surround inner word with backticks", noremap = true }
)
local wk = require("which-key")
wk.register({
sa = "Add surrounding",
sd = "Delete surrounding",
sh = "Highlight surrounding",
sn = "Surround update n lines",
sr = "Replace surrounding",
sF = "Find left surrounding",
sf = "Find right surrounding",
st = { "<cmd>lua require('tsht').nodes()<cr>", "TS hint textobject" },
})
-- TODO which-key integration
require("mini.surround").setup(opts)
end,
},
Expand Down
14 changes: 2 additions & 12 deletions lua/core/plugins/noice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ local default_config = {
-- { filter = { event = "msg_show", find = "written" }, opts = { skip = true } }, -- skip "write" message on save
},
},
groups = {
["<leader>n"] = { name = "Noice" },
},
keys = {
{ "<leader>n", "", desc = "Noice" },
{ "<leader>nd", "<cmd>Noice dismiss<cr>", desc = "Dismiss all visible messages" },
{ "<leader>nn", "<cmd>Noice<cr>", desc = "Open Noice" },
{ "<leader>ne", "<cmd>Noice errors<cr>", desc = "Open Noice Errors" },
Expand All @@ -47,19 +45,11 @@ return {
{
"rcarriga/nvim-notify",
opts = {
top_down = false,
top_down = true,
},
},
},
keys = config.keys,
opts = config.opts,
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = config.groups,
},
},
}
11 changes: 1 addition & 10 deletions lua/core/plugins/spectre.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ return {
},
enabled = vim.g.config.plugins.spectre.enable,
keys = {
{ "<leader>R", "", desc = "Replace" },
{
"<leader>Rr",
function()
Expand All @@ -30,14 +31,4 @@ return {
},
},
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = {
["<leader>R"] = { name = "Replace" },
},
},
},
}
11 changes: 1 addition & 10 deletions lua/core/plugins/treesj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ return {
{
"Wansmer/treesj",
keys = {
{ "<leader>mS", "", desc = "TreeSJ" },
{ "<leader>mSt", "<cmd>TSJToggle<cr>", desc = "Toggle" },
{ "<leader>mSj", "<cmd>TSJJoin<cr>", desc = "Join" },
{ "<leader>mSs", "<cmd>TSJSplit<cr>", desc = "Split" },
Expand All @@ -12,14 +13,4 @@ return {
},
config = true,
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = {
["<leader>mS"] = { name = "TreeSJ" },
},
},
},
}
12 changes: 1 addition & 11 deletions lua/core/plugins/trouble.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ local default_config = {
},
},
},
groups = {
["<leader>x"] = { name = "Trouble" },
},
keys = {
{ "<leader>x", "", desc = "Trouble" },
{
"<leader>xl",
"<cmd>Trouble loclist toggle<cr>",
Expand All @@ -43,12 +41,4 @@ return {
opts = config.opts,
keys = config.keys,
},
-- which key integration
{
"folke/which-key.nvim",
optional = true,
opts = {
groups = config.groups,
},
},
}
52 changes: 26 additions & 26 deletions lua/core/plugins/which-key.lua
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
local user_config = vim.g.config.plugins.which_key or {}
local icons = require("utils.icons")
local M = {
"folke/which-key.nvim",
event = "VeryLazy",

local default_config = {
opts = {
preset = "modern",
icons = {
rules = false, -- disable icons in keymaps
breadcrumb = icons.arrows.DoubleArrowRight, -- symbol used in the command line area that shows your active key combo
separator = icons.arrows.SmallArrowRight, -- symbol used between a key and it's label
group = icons.ui.Plus, -- symbol prepended to a group
},
window = {
border = "none", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = { 0, 10, 3, 10 }, -- extra window margin [top, right, bottom, left]
padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
},
layout = {
height = { min = 3, max = 25 }, -- min and max height of the columns
width = { min = 5, max = 50 }, -- min and max width of the columns
spacing = 10, -- spacing between columns
align = "center", -- align columns left, center or right
},
groups = {
mode = { "n", "v" },
["<leader>b"] = { name = "Buffers" },
["<leader>f"] = { name = "Files" },
["<leader>l"] = { name = "LSP" },
["<leader>m"] = { name = "Misc" },
["<leader>q"] = { name = "Quickfix" },
["<leader>R"] = { name = "Replace" },
["<leader>mS"] = { name = "TreeSJ" },
["<leader>s"] = { name = "Search" },
["<leader>t"] = { name = "Toggles" },
["<leader>w"] = { name = "Window" },
["<leader>z"] = { name = "Spelling" },
spec = {
{ "<leader>b", group = "Buffers" },
{ "<leader>f", group = "Files" },
{ "<leader>l", group = "LSP" },
{ "<leader>m", group = "Misc" },
{ "<leader>q", group = "Quickfix" },
{ "<leader>R", group = "Replace" },
{ "<leader>mS", group = "TreeSJ" },
{ "<leader>s", group = "Search" },
{ "<leader>t", group = "Toggles" },
{ "<leader>w", group = "Window" },
{ "<leader>z", group = "Spelling" },
},
},
}

local config = vim.tbl_deep_extend("force", default_config, user_config)

return {
"folke/which-key.nvim",
event = "VeryLazy",
opts_extend = { "spec" },
opts = config.opts,
config = function(_, opts)
local wk = require("which-key")
wk.setup(opts)
wk.register(opts.groups)
end,
}

return M

0 comments on commit 6e441f3

Please sign in to comment.