Files
dotfiles/dot_config/nvim/lua/plugins/dap.lua
T
2026-08-02 14:18:41 -04:00

81 lines
2.6 KiB
Lua

vim.pack.add({
{ src = "https://github.com/mfussenegger/nvim-dap" },
{ src = "https://github.com/rcarriga/nvim-dap-ui" },
{ src = "https://github.com/nvim-neotest/nvim-nio" },
})
local dap = require("dap")
local dapui = require("dapui")
local lldb_dap = vim.fn.exepath("lldb-dap")
if lldb_dap == "" then
vim.notify("lldb-dap not found — install lldb (pacman -S lldb)", vim.log.levels.WARN)
end
dap.adapters.lldb = {
type = "executable",
command = lldb_dap,
name = "lldb",
}
local function project_binary()
local cwd = vim.fn.getcwd()
return cwd .. "/" .. vim.fn.fnamemodify(cwd, ":t")
end
dap.configurations.odin = {
{
type = "lldb",
request = "launch",
name = "Launch Odin",
cwd = function()
return vim.fn.getcwd()
end,
program = project_binary,
},
}
dapui.setup({})
dap.listeners.after.event_initialized["dapui"] = dapui.open
dap.listeners.before.event_terminated["dapui"] = dapui.close
dap.listeners.before.event_exited["dapui"] = dapui.close
local function run_or_continue()
if dap.session() then
dap.continue()
elseif vim.bo.filetype == "odin" then
vim.system({ "odin", "build", ".", "-debug" }, { cwd = vim.fn.getcwd() }, function(obj)
if obj.code ~= 0 then
vim.notify("odin build failed (code " .. obj.code .. ")", vim.log.levels.ERROR)
return
end
dap.run(dap.configurations.odin[1])
end)
else
dap.continue()
end
end
local maps = {
{ "n", "<F5>", run_or_continue, "Start/Continue" },
{ "n", "<leader>dc", run_or_continue, "Start/Continue" },
{ "n", "<F10>", function() dap.step_over() end, "Step Over" },
{ "n", "<leader>do", function() dap.step_over() end, "Step Over" },
{ "n", "<F11>", function() dap.step_into() end, "Step Into" },
{ "n", "<leader>di", function() dap.step_into() end, "Step Into" },
{ "n", "<F12>", function() dap.step_out() end, "Step Out" },
{ "n", "<leader>dO", function() dap.step_out() end, "Step Out" },
{ "n", "<leader>db", function() dap.toggle_breakpoint() end, "Toggle Breakpoint" },
{ "n", "<leader>dB", function() dap.set_breakpoint(vim.fn.input("Condition: ")) end, "Conditional Breakpoint" },
{ "n", "<leader>dt", function() dap.terminate() end, "Terminate" },
{ "n", "<leader>dq", function() dap.close() end, "Close Session" },
{ "n", "<leader>dr", function() dap.repl.toggle() end, "REPL" },
{ "n", "<leader>du", function() dapui.toggle() end, "Toggle DAP UI" },
{ "n", "<leader>d?", function() dap.list_breakpoints() end, "List Breakpoints" },
}
for _, map in ipairs(maps) do
vim.keymap.set(map[1], map[2], map[3], { desc = "DAP: " .. map[4] })
end