hopefully working debugger
This commit is contained in:
@@ -1,67 +1,141 @@
|
|||||||
--[[
|
|
||||||
DEBUGGING.LUA
|
|
||||||
nvim-dap for Python and JavaScript/TypeScript debugging
|
|
||||||
Requirements:
|
|
||||||
Python: pip install debugpy
|
|
||||||
JS/TS: Build vscode-js-debug manually (see below)
|
|
||||||
]]
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ "mfussenegger/nvim-dap" },
|
{
|
||||||
{ "nvim-neotest/nvim-nio" },
|
"mfussenegger/nvim-dap",
|
||||||
{
|
},
|
||||||
"rcarriga/nvim-dap-ui",
|
{
|
||||||
dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" },
|
"rcarriga/nvim-dap-ui",
|
||||||
config = function()
|
dependencies = "nvim-neotest/nvim-nio",
|
||||||
local dap, dapui = require("dap"), require("dapui")
|
},
|
||||||
dapui.setup()
|
{
|
||||||
dap.listeners.after.event_initialized["dapui_config"] = dapui.open
|
"theHamsta/nvim-dap-virtual-text",
|
||||||
vim.keymap.set("n", "<F5>", dap.continue, { desc = "Continue" })
|
dependencies = "mfussenegger/nvim-dap",
|
||||||
vim.keymap.set("n", "<F10>", dap.step_over, { desc = "Step over" })
|
},
|
||||||
vim.keymap.set("n", "<F11>", dap.step_into, { desc = "Step into" })
|
{
|
||||||
vim.keymap.set("n", "<S-F11>", dap.step_out, { desc = "Step out" })
|
"mfussenegger/nvim-dap-python",
|
||||||
vim.keymap.set("n", "<F9>", dap.toggle_breakpoint, { desc = "Breakpoint" })
|
dependencies = "mfussenegger/nvim-dap",
|
||||||
vim.keymap.set("n", "<leader>du", dapui.toggle, { desc = "DAP UI" })
|
config = function()
|
||||||
end,
|
local dap = require("dap")
|
||||||
},
|
local dapui = require("dapui")
|
||||||
{ "mfussenegger/nvim-dap-python", dependencies = { "mfussenegger/nvim-dap" } },
|
require("dap-python").setup()
|
||||||
|
|
||||||
|
dapui.setup({
|
||||||
|
icons = { expanded = "▾", collapsed = "▸", current_frame = "▸" },
|
||||||
|
mappings = {
|
||||||
|
expand = { "<CR>", "<2-LeftMouse>" },
|
||||||
|
open = "o",
|
||||||
|
remove = "d",
|
||||||
|
edit = "e",
|
||||||
|
repl = "r",
|
||||||
|
toggle = "t",
|
||||||
|
},
|
||||||
|
expand_lines = vim.fn.has("nvim-0.7") == 1,
|
||||||
|
layouts = {
|
||||||
|
{
|
||||||
|
elements = {
|
||||||
|
{ id = "scopes", size = 0.25 },
|
||||||
|
{ id = "breakpoints", size = 0.25 },
|
||||||
|
{ id = "stacks", size = 0.25 },
|
||||||
|
{ id = "watches", size = 0.25 },
|
||||||
|
},
|
||||||
|
size = 0.25,
|
||||||
|
position = "right",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
elements = {
|
||||||
|
{ id = "repl", size = 0.5 },
|
||||||
|
{ id = "console", size = 0.5 },
|
||||||
|
},
|
||||||
|
position = "bottom",
|
||||||
|
size = 0.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
floating = {
|
||||||
|
max_height = nil,
|
||||||
|
max_width = nil,
|
||||||
|
border = "rounded",
|
||||||
|
mappings = {
|
||||||
|
close = { "q", "<Esc>" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
windows = { indent = 1 },
|
||||||
|
})
|
||||||
|
|
||||||
|
dap.listeners.after.event_initialized["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
|
||||||
|
|
||||||
|
dap.configurations.python = {
|
||||||
|
{
|
||||||
|
type = "python",
|
||||||
|
request = "launch",
|
||||||
|
name = "Launch file",
|
||||||
|
program = "${file}",
|
||||||
|
pythonPath = function()
|
||||||
|
return vim.fn.exepath("python3") or "python"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "python",
|
||||||
|
request = "launch",
|
||||||
|
name = "Debug current file (integrated terminal)",
|
||||||
|
program = "${file}",
|
||||||
|
console = "integratedTerminal",
|
||||||
|
pythonPath = function()
|
||||||
|
return vim.fn.exepath("python3") or "python"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "python",
|
||||||
|
request = "launch",
|
||||||
|
name = "Debug with arguments",
|
||||||
|
program = "${file}",
|
||||||
|
args = function()
|
||||||
|
local args = vim.fn.input("Args: ", ""):split(" ")
|
||||||
|
return args
|
||||||
|
end,
|
||||||
|
console = "integratedTerminal",
|
||||||
|
pythonPath = function()
|
||||||
|
return vim.fn.exepath("python3") or "python"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "python",
|
||||||
|
request = "launch",
|
||||||
|
name = "Debug test_api.py",
|
||||||
|
module = "unittest",
|
||||||
|
args = { "test.test_api", "-v" },
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
pythonPath = function()
|
||||||
|
return vim.fn.exepath("python3") or "python"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "python",
|
||||||
|
request = "launch",
|
||||||
|
name = "Debug all tests",
|
||||||
|
module = "unittest",
|
||||||
|
args = { "discover", "-s", "test", "-v" },
|
||||||
|
cwd = "${workspaceFolder}",
|
||||||
|
pythonPath = function()
|
||||||
|
return vim.fn.exepath("python3") or "python"
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>db", dap.toggle_breakpoint, { desc = "Toggle breakpoint" })
|
||||||
|
vim.keymap.set("n", "<leader>dc", dap.continue, { desc = "Continue" })
|
||||||
|
vim.keymap.set("n", "<leader>ds", dap.step_over, { desc = "Step over" })
|
||||||
|
vim.keymap.set("n", "<leader>di", dap.step_into, { desc = "Step into" })
|
||||||
|
vim.keymap.set("n", "<leader>do", dap.step_out, { desc = "Step out" })
|
||||||
|
vim.keymap.set("n", "<leader>dr", dap.repl.open, { desc = "Open REPL" })
|
||||||
|
vim.keymap.set("n", "<leader>dl", dap.run_last, { desc = "Run last debug config" })
|
||||||
|
vim.keymap.set("n", "<leader>du", dapui.toggle, { desc = "Toggle DAP UI" })
|
||||||
|
end,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
--[[
|
|
||||||
To enable JS/TS debugging:
|
|
||||||
|
|
||||||
1. Build vscode-js-debug:
|
|
||||||
git clone https://github.com/microsoft/vscode-js-debug
|
|
||||||
cd vscode-js-debug
|
|
||||||
npm install --legacy-peer-deps
|
|
||||||
npx gulp vsDebugServerBundle && mv dist out
|
|
||||||
|
|
||||||
2. Add this plugin (uncomment inside the return block above):
|
|
||||||
{
|
|
||||||
"mxsdev/nvim-dap-vscode-js",
|
|
||||||
dependencies = { "mfussenegger/nvim-dap" },
|
|
||||||
config = function()
|
|
||||||
require("dap-vscode-js").setup({
|
|
||||||
adapters = { "pwa-node", "pwa-chrome" },
|
|
||||||
})
|
|
||||||
for _, language in ipairs({ "typescript", "javascript" }) do
|
|
||||||
require("dap").configurations[language] = {
|
|
||||||
{
|
|
||||||
type = "pwa-node",
|
|
||||||
request = "launch",
|
|
||||||
name = "Launch file",
|
|
||||||
program = "${file}",
|
|
||||||
cwd = "${workspaceFolder}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "pwa-node",
|
|
||||||
request = "attach",
|
|
||||||
name = "Attach to process",
|
|
||||||
processId = require("dap.utils").pick_process,
|
|
||||||
cwd = "${workspaceFolder}",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
--]]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user