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 { return {
"rcarriga/nvim-dap-ui", "rcarriga/nvim-dap-ui",
dependencies = { dependencies = {
"mfussenegger/nvim-dap", "mfussenegger/nvim-dap",
"nvim-neotest/nvim-nio", "nvim-neotest/nvim-nio",
"jay-babu/mason-nvim-dap.nvim" "jay-babu/mason-nvim-dap.nvim"
}, },
config = function() keys = {
local dap, dapui = require("dap"), require("dapui") {
dapui.setup(); "<leader>db",
dap.listeners.before.attach.dapui_config = function() function() require("dap").toggle_breakpoint() end,
dapui.open() desc = "Toggle Breakpoint"
end },
dap.listeners.before.launch.dapui_config = function() {
dapui.open() "<leader>dc",
end function() require("dap").continue() end,
dap.listeners.before.event_terminated.dapui_config = function() desc = "Continue"
dapui.close() },
end {
dap.listeners.before.event_exited.dapui_config = function() "<leader>dC",
dapui.close() function() require("dap").run_to_cursor() end,
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) -- C/C++/Rust (via gdb)
dap.adapters.gdb = { dap.adapters.gdb = {
type = "executable", type = "executable",
command = "gdb", command = "gdb",
args = { "--interpreter=dap", "--eval-command", "set print pretty on" } args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
} }
local c_conf = { local c_conf = {
{ {
name = "Launch", name = "Launch",
type = "gdb", type = "gdb",
request = "launch", request = "launch",
program = function() program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end, end,
cwd = "${workspaceFolder}", cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false, stopAtBeginningOfMainSubprogram = false,
}, },
{ {
name = "Select and attach to process", name = "Select and attach to process",
type = "gdb", type = "gdb",
request = "attach", request = "attach",
program = function() program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end, end,
pid = function() pid = function()
local name = vim.fn.input('Executable name (filter): ') local name = vim.fn.input('Executable name (filter): ')
return require("dap.utils").pick_process({ filter = name }) return require("dap.utils").pick_process({ filter = name })
end, end,
cwd = '${workspaceFolder}' cwd = '${workspaceFolder}'
}, },
{ {
name = 'Attach to gdbserver :1234', name = 'Attach to gdbserver :1234',
type = 'gdb', type = 'gdb',
request = 'attach', request = 'attach',
target = 'localhost:1234', target = 'localhost:1234',
program = function() program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end, end,
cwd = '${workspaceFolder}' cwd = '${workspaceFolder}'
}, },
} }
dap.configurations.c = c_conf dap.configurations.c = c_conf
dap.configurations.cpp = c_conf dap.configurations.cpp = c_conf
end end
} }