From fcd3cf33ed9b254c3c145f89b386e8bd0ad65d5e Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 30 Mar 2026 23:42:24 +0200 Subject: Add debbugging tools plugins --- lua/ache/plugins/dap/dap.lua | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 lua/ache/plugins/dap/dap.lua (limited to 'lua/ache/plugins/dap/dap.lua') diff --git a/lua/ache/plugins/dap/dap.lua b/lua/ache/plugins/dap/dap.lua new file mode 100644 index 0000000..e466921 --- /dev/null +++ b/lua/ache/plugins/dap/dap.lua @@ -0,0 +1,144 @@ +--[ +--This plugin add support for Debug Adapter Protocol to connect to various debugger +-- +-- C\C++ => gdb => via ... +-- GoLang => delve => via nvim-dap-go +-- Python => XXXXX => via XXXX +--] + +return { + "https://codeberg.org/mfussenegger/nvim-dap.git", + + dependencies = { + "rcarriga/nvim-dap-ui", + "leoluz/nvim-dap-go", + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") + + dapui.setup() + require("dap-go").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 + + if vim.fn.executable("codelldb") == 1 then + dap.adapters.codelldb = { + type = "server", + port = "${port}", + executable = { + command = "codelldb", -- or if not in $PATH: "/absolute/path/to/codelldb" + args = { "--port", "${port}" }, + + -- On windows you may have to uncomment this: + -- detached = false, + }, + } + end + + if vim.fn.executable("gdb") == 1 then + dap.adapters.gdb = { + id = "gdb", + type = "executable", + command = "gdb", + args = { "--quiet", "--interpreter=dap" }, + } + end + + dap.configurations.cpp = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + }, + } + + dap.configurations.c = dap.configurations.cpp + -- dap.configurations.rust = dap.configurations.cpp + + -- dap.configurations.c = { + -- { + -- name = "Run executable (GDB)", + -- type = "gdb", + -- request = "launch", + -- -- This requires special handling of 'run_last', see + -- -- https://github.com/mfussenegger/nvim-dap/issues/1025#issuecomment-1695852355 + -- program = function() + -- local path = vim.fn.input({ + -- prompt = "Path to executable: ", + -- default = vim.fn.getcwd() .. "/", + -- completion = "file", + -- }) + -- + -- return (path and path ~= "") and path or dap.ABORT + -- end, + -- }, + -- { + -- name = "Run executable with arguments (GDB)", + -- type = "gdb", + -- request = "launch", + -- -- This requires special handling of 'run_last', see + -- -- https://github.com/mfussenegger/nvim-dap/issues/1025#issuecomment-1695852355 + -- program = function() + -- local path = vim.fn.input({ + -- prompt = "Path to executable: ", + -- default = vim.fn.getcwd() .. "/", + -- completion = "file", + -- }) + -- + -- return (path and path ~= "") and path or dap.ABORT + -- end, + -- args = function() + -- local args_str = vim.fn.input({ + -- prompt = "Arguments: ", + -- }) + -- return vim.split(args_str, " +") + -- end, + -- }, + -- { + -- name = "Attach to process (GDB)", + -- type = "gdb", + -- request = "attach", + -- processId = require("dap.utils").pick_process, + -- }, + -- } + + -- Adds keymaps + vim.keymap.set("n", "Dt", dap.toggle_breakpoint, { desc = "Debugger toggle breakpoint" }) + vim.keymap.set("n", "Dc", dap.continue, { desc = "Debugger continue" }) + end, +} + +-- return { +-- "https://codeberg.org/mfussenegger/nvim-dap.git", +-- enabled = true, +-- config = function() +-- if vim.fn.executable("gdb") == 1 then +-- local dap = require("dap").setup() +-- dap.adapters.gdb = { +-- id = "gdb", +-- type = "executable", +-- command = "gdb", +-- args = { "--quiet", "--interpreter=dap" }, +-- } + +-- end +-- end, +-- } +-- -- cgit v1.3-2-g11bf