From 6e884786ed7efd57341f3153d04b1efa5c00631c Mon Sep 17 00:00:00 2001 From: xesc Date: Mon, 16 Jun 2025 08:41:20 +0200 Subject: [PATCH] add dap plugin, remove old keymaps --- lua/core/remap.lua | 14 ------- lua/plugin/dap.lua | 100 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 lua/plugin/dap.lua diff --git a/lua/core/remap.lua b/lua/core/remap.lua index eac099d..51b6888 100644 --- a/lua/core/remap.lua +++ b/lua/core/remap.lua @@ -22,16 +22,6 @@ vim.api.nvim_set_keymap("n", "bd", "bd", {}) vim.api.nvim_set_keymap("n", "bn", "bnext", {}) vim.api.nvim_set_keymap("n", "bp", "bprevious", {}) --- quickfix and locationlist -vim.api.nvim_set_keymap("n", "", "cnextzz", {}) -vim.api.nvim_set_keymap("n", "", "cprevzz", {}) -vim.api.nvim_set_keymap("n", "h", "lnextzz", {}) -vim.api.nvim_set_keymap("n", "l", "lprevzz", {}) -vim.api.nvim_set_keymap("n", "L", "lcl", {}) -vim.api.nvim_set_keymap("n", "Q", "cw", {}) -vim.api.nvim_set_keymap("n", "q", "ccl", {}) - - -- moving visual blocks vim.api.nvim_set_keymap("v", "J", ":m '>+1gv=gv", {}) vim.api.nvim_set_keymap("v", "K", ":m '<-2gv=gv", {}) @@ -51,10 +41,6 @@ vim.api.nvim_set_keymap("n", "Y", "\"+Y", {}) -- paste from system clipboard vim.api.nvim_set_keymap("n", "P", "\"+p", {}) --- make current file (un)executable -vim.api.nvim_set_keymap("n", "mx", ":exec 'w' !chmod +x %", { silent = true }) -vim.api.nvim_set_keymap("n", "mX", ":exec 'w' !chmod -x %", { silent = true }) - -- for fast save vim.api.nvim_set_keymap("n", "", ":exec 'w'", {silent = true}) diff --git a/lua/plugin/dap.lua b/lua/plugin/dap.lua new file mode 100644 index 0000000..547b76f --- /dev/null +++ b/lua/plugin/dap.lua @@ -0,0 +1,100 @@ +return { + { + "mfussenegger/nvim-dap", + dependencies = { + "igorlfs/nvim-dap-view", + opts = { + windows = { + terminal = { + hide = { "c" }, + start_hidden = true, + }, + } + } + }, + config = function() + local dap, dv = require("dap"), require("dap-view") + + dap.set_log_level("DEBUG") + vim.keymap.set("n", "Dc", dap.continue, { desc = "Debug: Continue" }) + vim.keymap.set("n", "Dsn", dap.step_over, { desc = "Debug: Step Over (Next)" }) + vim.keymap.set("n", "Dsi", dap.step_into, { desc = "Debug: Step Into" }) + vim.keymap.set("n", "Dso", dap.step_out, { desc = "Debug: Step Out" }) + vim.keymap.set("n", "B", dap.toggle_breakpoint, { desc = "Debug: Toggle Breakpoint" }) + vim.keymap.set("n", "Dv", "DapViewToggle", { desc = "Debug: Toggle Debug View" }) + + dap.listeners.before.attach["dap-view-config"] = function() + dv.open() + end + dap.listeners.before.launch["dap-view-config"] = function() + dv.open() + end + dap.listeners.before.event_terminated["dap-view-config"] = function() + dv.close() + end + dap.listeners.before.event_exited["dap-view-config"] = function() + dv.close() + end + + dap.adapters.gdb = { + type = "executable", + command = "gdb", + args = { "--interpreter=dap", "--eval-command", "set print pretty on" } + } + dap.configurations.c = { + { + 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}' + }, + } + end, + }, + { + "jay-babu/mason-nvim-dap.nvim", + dependencies = { + "mfussenegger/nvim-dap", + "williamboman/mason.nvim", + }, + config = function() + require('mason-nvim-dap').setup({ + handlers = { + function(config) + -- all sources with no handler get passed here + + -- Keep original functionality + require('mason-nvim-dap').default_setup(config) + end, + }, + }) + end, + } +}