107 lines
3.3 KiB
Lua
107 lines
3.3 KiB
Lua
-- Adapter paths come from the home-manager module (NVIM_* variables).
|
|
local function setup_adapters(dap)
|
|
local env = vim.env
|
|
|
|
-- Rust
|
|
dap.adapters.codelldb = { type = "executable", command = env.NVIM_CODELLDB or "codelldb" }
|
|
dap.configurations.rust = {
|
|
{
|
|
name = "Launch binary",
|
|
type = "codelldb",
|
|
request = "launch",
|
|
program = function()
|
|
return vim.fn.input("Binary: ", vim.fn.getcwd() .. "/target/debug/", "file")
|
|
end,
|
|
cwd = "${workspaceFolder}",
|
|
},
|
|
}
|
|
|
|
-- Go
|
|
dap.adapters.delve = {
|
|
type = "server",
|
|
port = "${port}",
|
|
executable = { command = "dlv", args = { "dap", "-l", "127.0.0.1:${port}" } },
|
|
}
|
|
dap.configurations.go = {
|
|
{ name = "Debug file", type = "delve", request = "launch", program = "${file}" },
|
|
{ name = "Debug package", type = "delve", request = "launch", program = "${fileDirname}" },
|
|
{ name = "Debug test", type = "delve", request = "launch", mode = "test", program = "${fileDirname}" },
|
|
}
|
|
|
|
-- TypeScript / JavaScript
|
|
dap.adapters["pwa-node"] = {
|
|
type = "server",
|
|
host = "127.0.0.1",
|
|
port = "${port}",
|
|
executable = { command = "js-debug", args = { "${port}", "127.0.0.1" } },
|
|
}
|
|
local js = {
|
|
{ name = "Launch file", type = "pwa-node", request = "launch", program = "${file}", cwd = "${workspaceFolder}" },
|
|
{ name = "Attach", type = "pwa-node", request = "attach", processId = require("dap.utils").pick_process },
|
|
}
|
|
for _, ft in ipairs({ "javascript", "typescript", "javascriptreact", "typescriptreact" }) do
|
|
dap.configurations[ft] = js
|
|
end
|
|
|
|
-- Python
|
|
dap.adapters.python = {
|
|
type = "executable",
|
|
command = env.NVIM_DEBUGPY_PYTHON or "python3",
|
|
args = { "-m", "debugpy.adapter" },
|
|
}
|
|
dap.configurations.python = {
|
|
{
|
|
name = "Launch file",
|
|
type = "python",
|
|
request = "launch",
|
|
program = "${file}",
|
|
pythonPath = function()
|
|
local venv = env.VIRTUAL_ENV or (vim.fn.getcwd() .. "/.venv")
|
|
local py = venv .. "/bin/python"
|
|
return vim.fn.executable(py) == 1 and py or "python3"
|
|
end,
|
|
},
|
|
}
|
|
|
|
-- PHP (Xdebug)
|
|
dap.adapters.php = {
|
|
type = "executable",
|
|
command = env.NVIM_NODE or "node",
|
|
args = { env.NVIM_PHP_DEBUG },
|
|
}
|
|
dap.configurations.php = {
|
|
{ name = "Listen for Xdebug", type = "php", request = "launch", port = 9003 },
|
|
}
|
|
end
|
|
|
|
local function dap(fn)
|
|
return function()
|
|
require("dap")[fn]()
|
|
end
|
|
end
|
|
|
|
return {
|
|
{
|
|
"mfussenegger/nvim-dap",
|
|
cond = vim.g.profile == "full",
|
|
dependencies = { "rcarriga/nvim-dap-ui", "nvim-neotest/nvim-nio" },
|
|
keys = {
|
|
{ "<leader>db", dap("toggle_breakpoint"), desc = "Toggle breakpoint" },
|
|
{ "<leader>dc", dap("continue"), desc = "Continue" },
|
|
{ "<leader>di", dap("step_into"), desc = "Step into" },
|
|
{ "<leader>do", dap("step_over"), desc = "Step over" },
|
|
{ "<leader>dO", dap("step_out"), desc = "Step out" },
|
|
{ "<leader>dq", dap("terminate"), desc = "Terminate" },
|
|
{ "<leader>du", function() require("dapui").toggle() end, desc = "Toggle debug UI" },
|
|
},
|
|
config = function()
|
|
local d, ui = require("dap"), require("dapui")
|
|
ui.setup()
|
|
d.listeners.after.event_initialized.dapui = ui.open
|
|
d.listeners.before.event_terminated.dapui = ui.close
|
|
d.listeners.before.event_exited.dapui = ui.close
|
|
setup_adapters(d)
|
|
end,
|
|
},
|
|
}
|