Added keyboard shortcuts for dap

This commit is contained in:
Warwick New 2026-07-23 15:36:06 +01:00
parent f33ba61238
commit 0b06534484

View file

@ -1,69 +1,121 @@
return {
"rcarriga/nvim-dap-ui",
dependencies = {
"mfussenegger/nvim-dap",
"nvim-neotest/nvim-nio",
"jay-babu/mason-nvim-dap.nvim"
},
config = function()
local dap, dapui = require("dap"), require("dapui")
dapui.setup();
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
"rcarriga/nvim-dap-ui",
dependencies = {
"mfussenegger/nvim-dap",
"nvim-neotest/nvim-nio",
"jay-babu/mason-nvim-dap.nvim"
},
keys = {
{
"<leader>db",
function() require("dap").toggle_breakpoint() end,
desc = "Toggle Breakpoint"
},
{
"<leader>dc",
function() require("dap").continue() end,
desc = "Continue"
},
{
"<leader>dC",
function() require("dap").run_to_cursor() end,
desc = "Run to Cursor"
},
{
"<leader>dT",
function() require("dap").terminate() end,
desc = "Terminate"
},
{
"<leader>dn",
function() require("dap").step_over() end,
desc = "Step Over"
},
{
"<leader>di",
function() require("dap").step_into() end,
desc = "Step Into"
},
{
"<leader>do",
function() require("dap").step_out() end,
desc = "Step Out"
},
{
"<leader>dl",
function() require("dap").run_last() end,
desc = "Run Last Program"
},
{
"<leader>dk",
function() require("dap.ui.widgets").hover() end,
desc = "Hover"
},
{
"<leader>dp",
function() require("dap.ui.widgets").preview() end,
desc = "Preview"
},
},
config = function()
local dap, dapui = require("dap"), require("dapui")
dapui.setup();
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
-- C/C++/Rust (via gdb)
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
}
-- C/C++/Rust (via gdb)
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
}
local c_conf = {
{
name = "Launch",
type = "gdb",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
{
name = "Select and attach to process",
type = "gdb",
request = "attach",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
pid = function()
local name = vim.fn.input('Executable name (filter): ')
return require("dap.utils").pick_process({ filter = name })
end,
cwd = '${workspaceFolder}'
},
{
name = 'Attach to gdbserver :1234',
type = 'gdb',
request = 'attach',
target = 'localhost:1234',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}'
},
}
dap.configurations.c = c_conf
dap.configurations.cpp = c_conf
end
local c_conf = {
{
name = "Launch",
type = "gdb",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
{
name = "Select and attach to process",
type = "gdb",
request = "attach",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
pid = function()
local name = vim.fn.input('Executable name (filter): ')
return require("dap.utils").pick_process({ filter = name })
end,
cwd = '${workspaceFolder}'
},
{
name = 'Attach to gdbserver :1234',
type = 'gdb',
request = 'attach',
target = 'localhost:1234',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}'
},
}
dap.configurations.c = c_conf
dap.configurations.cpp = c_conf
end
}