116 lines
3.8 KiB
Lua
116 lines
3.8 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 = { "igorlfs/nvim-dap-view" },
|
|
keys = {
|
|
{ "<leader>db", dap("toggle_breakpoint"), desc = "Toggle breakpoint" },
|
|
{
|
|
"<leader>dB",
|
|
function() require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) end,
|
|
desc = "Conditional breakpoint",
|
|
},
|
|
{ "<leader>dr", function() require("dap").repl.open() end, desc = "Open REPL" },
|
|
{ "<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>dv", function() require("dap-view").toggle() end, desc = "Toggle debug view" },
|
|
},
|
|
config = function()
|
|
local sign = vim.fn.sign_define
|
|
sign("DapBreakpoint", { text = "●", texthl = "DapBreakpoint" })
|
|
sign("DapBreakpointCondition", { text = "◆", texthl = "DapBreakpointCondition" })
|
|
sign("DapBreakpointRejected", { text = "✖", texthl = "DapBreakpointRejected" })
|
|
sign("DapLogPoint", { text = "◆", texthl = "DapLogPoint" })
|
|
sign("DapStopped", { text = "▶", texthl = "DapStopped", linehl = "debugPC" })
|
|
|
|
require("dap-view").setup({ auto_toggle = true })
|
|
setup_adapters(require("dap"))
|
|
end,
|
|
},
|
|
}
|