Skip to content

Commit 10139a3

Browse files
committed
feat: configurable keymaps (WIP) (#159)
1 parent 6e7c49a commit 10139a3

12 files changed

Lines changed: 187 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Start a regular debugging session. When desired, you can use `:DapViewOpen` to s
7171

7272
Once you're done debugging, you can close the plugin with `:DapViewClose` and then terminate your session as usual.
7373

74-
There's a lot more you can do: `nvim-dap-view` is highly customizable. To learn all the options, commands, tips and tricks, visit the full documentation on the [website](https://igorlfs.github.io/nvim-dap-view/home).
74+
There's a lot more you can do: `nvim-dap-view` is highly customizable. To learn all the options, commands, tips and tricks, visit the full documentation on the [website](https://igorlfs.github.io/nvim-dap-view/home) or use the built-in help doc via `:help dap-view.txt`.
7575

7676
## Contributing
7777

doc/dap-view.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,29 @@ You don't have to copy and paste these options. Use them as a reference.
146146
hide = {},
147147
},
148148
},
149+
-- WIP: some keymaps are not overrideable yet!
150+
keymaps = {
151+
hover = {
152+
quit = "q",
153+
toggle = { "<CR>", "<2-LeftMouse>" },
154+
jump_to_parent = "[[",
155+
set_value = "s",
156+
},
157+
help = {
158+
quit = "q",
159+
},
160+
console = {
161+
next_session = "]s",
162+
prev_session = "[s",
163+
},
164+
base = {
165+
next_view = "]v",
166+
prev_view = "[v",
167+
jump_to_first = "[V",
168+
jump_to_last = "]V",
169+
help = "g?",
170+
},
171+
},
149172
icons = {
150173
collapsed = "󰅂 ",
151174
disabled = "",

docs/src/routes/configuration/+page.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ return {
6767
hide = {},
6868
},
6969
},
70+
-- WIP: some keymaps are not overrideable yet!
71+
keymaps = {
72+
hover = {
73+
quit = "q",
74+
toggle = { "<CR>", "<2-LeftMouse>" },
75+
jump_to_parent = "[[",
76+
set_value = "s",
77+
},
78+
help = {
79+
quit = "q",
80+
},
81+
console = {
82+
next_session = "]s",
83+
prev_session = "[s",
84+
},
85+
base = {
86+
next_view = "]v",
87+
prev_view = "[v",
88+
jump_to_first = "[V",
89+
jump_to_last = "]V",
90+
help = "g?",
91+
},
92+
},
7093
icons = {
7194
collapsed = "󰅂 ",
7295
disabled = "",

docs/src/routes/keymaps/+page.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ There are also some default keybindings for navigating to other views.
88

99
The help window itself has only 1 mapping: it can be closed with `q`.
1010

11+
**Some keymaps are overridable**. Check the [config](configuration) for details.
12+
1113
| Key | Action |
1214
| ------ | -------------------------------------------- |
1315
| **Threads** |

lua/dap-view/config.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ local M = {}
9393
---@field threads dapview.RenderThreadsConfig
9494
---@field breakpoints dapview.RenderBreakpointsConfig
9595

96+
---@alias dapview.Keymap string|string[]
97+
98+
---@class dapview.HoverKeymapsConfig
99+
---@field quit dapview.Keymap
100+
---@field toggle dapview.Keymap
101+
---@field jump_to_parent dapview.Keymap
102+
---@field set_value dapview.Keymap
103+
104+
---@class dapview.HelpKeymapsConfig
105+
---@field quit dapview.Keymap
106+
107+
---@class dapview.ConsoleKeymapsConfig
108+
---@field next_session dapview.Keymap
109+
---@field prev_session dapview.Keymap
110+
111+
---@class dapview.BaseKeymapsConfig
112+
---@field next_view dapview.Keymap
113+
---@field prev_view dapview.Keymap
114+
---@field jump_to_first dapview.Keymap
115+
---@field jump_to_last dapview.Keymap
116+
---@field help dapview.Keymap
117+
118+
---@class dapview.KeymapsConfig
119+
---@field hover dapview.HoverKeymapsConfig
120+
---@field help dapview.HelpKeymapsConfig
121+
---@field console dapview.ConsoleKeymapsConfig
122+
---@field base dapview.BaseKeymapsConfig
123+
96124
---@class dapview.VirtualTextConfig
97125
---@field enabled boolean
98126
---@field format fun(variable: dap.Variable, frame: dap.StackFrame, node: TSNode): string?
@@ -105,6 +133,7 @@ local M = {}
105133
---@field windows dapview.WindowsConfig
106134
---@field help dapview.HelpConfig
107135
---@field render dapview.RenderConfig
136+
---@field keymaps dapview.KeymapsConfig
108137
---@field icons dapview.IconsConfig Icons for each button
109138
---@field virtual_text dapview.VirtualTextConfig
110139
---@field switchbuf string|dapview.SwitchBufFun Control how to jump when selecting a breakpoint or a call in the stack
@@ -155,6 +184,28 @@ M.config = {
155184
hide = {},
156185
},
157186
},
187+
keymaps = {
188+
hover = {
189+
quit = "q",
190+
toggle = { "<CR>", "<2-LeftMouse>" },
191+
jump_to_parent = "[[",
192+
set_value = "s",
193+
},
194+
help = {
195+
quit = "q",
196+
},
197+
console = {
198+
next_session = "]s",
199+
prev_session = "[s",
200+
},
201+
base = {
202+
next_view = "]v",
203+
prev_view = "[v",
204+
jump_to_first = "[V",
205+
jump_to_last = "]V",
206+
help = "g?",
207+
},
208+
},
158209
icons = {
159210
collapsed = "󰅂 ",
160211
disabled = "",

lua/dap-view/console/keymaps.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
local setup = require("dap-view.setup")
2+
13
local keymap = require("dap-view.views.keymaps.util").keymap
24

35
local M = {}
46

57
---@param buf integer
68
M.set_keymaps = function(buf)
7-
keymap("]s", function()
9+
local keys = setup.config.keymaps.console
10+
11+
keymap(keys.next_session, function()
812
require("dap-view").navigate({ count = vim.v.count1, wrap = true, type = "sessions" })
913
end, buf)
1014

11-
keymap("[s", function()
15+
keymap(keys.prev_session, function()
1216
require("dap-view").navigate({ count = -vim.v.count1, wrap = true, type = "sessions" })
1317
end, buf)
1418
end

lua/dap-view/hover/init.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local state = require("dap-view.state")
2+
local setup = require("dap-view.setup")
23

34
local keymap = require("dap-view.views.keymaps.util").keymap
45

@@ -32,9 +33,11 @@ end
3233

3334
---@param bufnr integer
3435
M.set_keymaps = function(bufnr)
35-
keymap("q", "<C-w>q", bufnr)
36+
local keys = setup.config.keymaps.hover
3637

37-
keymap({ "<CR>", "<2-LeftMouse>" }, function()
38+
keymap(keys.quit, "<C-w>q", bufnr)
39+
40+
keymap(keys.toggle, function()
3841
local cursor_line = api.nvim_win_get_cursor(state.hover_winnr)[1]
3942

4043
coroutine.wrap(function()
@@ -49,13 +52,13 @@ M.set_keymaps = function(bufnr)
4952
end)()
5053
end, bufnr)
5154

52-
keymap("[[", function()
55+
keymap(keys.jump_to_parent, function()
5356
local cursor_line = api.nvim_win_get_cursor(state.hover_winnr)[1]
5457

5558
require("dap-view.hover.actions").jump_to_parent(cursor_line)
5659
end, bufnr)
5760

58-
keymap("s", function()
61+
keymap(keys.set_value, function()
5962
local cursor_line = api.nvim_win_get_cursor(state.hover_winnr)[1]
6063

6164
coroutine.wrap(function()

lua/dap-view/setup/validate/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function M.validate(config)
88
help = { config.help, "table" },
99
render = { config.render, "table" },
1010
switchbuf = { config.switchbuf, { "string", "function" } },
11+
keymaps = { config.keymaps, { "table" } },
1112
icons = { config.icons, "table" },
1213
virtual_text = { config.virtual_text, "table" },
1314
auto_toggle = { config.auto_toggle, { "boolean", "string" } },
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local M = {}
2+
3+
local validate = require("dap-view.setup.validate.util").validate
4+
5+
---@param config dapview.KeymapsConfig
6+
function M.validate(config)
7+
validate("keymaps", {
8+
hover = { config.hover, "table" },
9+
}, config)
10+
11+
local hover = config.hover
12+
validate("keymaps.hover", {
13+
quit = { hover.quit, { "table", "string" } },
14+
set_value = { hover.set_value, { "table", "string" } },
15+
jump_to_parent = { hover.jump_to_parent, { "table", "string" } },
16+
toggle = { hover.toggle, { "table", "string" } },
17+
}, config)
18+
19+
local help = config.help
20+
validate("keymaps.help", {
21+
quit = { help.quit, { "table", "string" } },
22+
}, config)
23+
24+
local console = config.console
25+
validate("keymaps.console", {
26+
next_session = { console.next_session, { "table", "string" } },
27+
prev_session = { console.prev_session, { "table", "string" } },
28+
}, config)
29+
30+
local base = config.base
31+
validate("keymaps.base", {
32+
next_view = { base.next_view, { "table", "string" } },
33+
prev_view = { base.prev_view, { "table", "string" } },
34+
jump_to_first = { base.jump_to_first, { "table", "string" } },
35+
jump_to_last = { base.jump_to_last, { "table", "string" } },
36+
help = { base.help, { "table", "string" } },
37+
}, config)
38+
end
39+
40+
return M

lua/dap-view/types.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525

2626
---@class dapview.VirtualTextConfigPartial : dapview.VirtualTextConfig, {}
2727

28+
---@class dapview.HoverKeymapsConfigPartial : dapview.HoverKeymapsConfig, {}
29+
30+
---@class dapview.HelpKeymapsConfigPartial : dapview.HelpKeymapsConfig, {}
31+
32+
---@class dapview.ConsoleKeymapsConfigPartial : dapview.ConsoleKeymapsConfig, {}
33+
34+
---@class dapview.BaseKeymapsConfigPartial : dapview.BaseKeymapsConfig, {}
35+
36+
---@class dapview.KeymapsConfigPartial : dapview.KeymapsConfig, {}
37+
---@field hover? dapview.HoverKeymapsConfigPartial
38+
---@field help? dapview.HelpKeymapsConfigPartial
39+
---@field console? dapview.ConsoleKeymapsConfigPartial
40+
---@field base? dapview.BaseKeymapsConfigPartial
41+
2842
---@class dapview.Config : dapview.ConfigStrict, {}
2943
---@field winbar? dapview.WinbarConfigPartial
3044
---@field windows? dapview.WindowsConfigPartial

0 commit comments

Comments
 (0)