added go dap

This commit is contained in:
Radu Macocian (admac)
2026-06-26 10:29:35 +02:00
parent c6739ea0da
commit 287defca42
2 changed files with 123 additions and 1 deletions
+8 -1
View File
@@ -10,6 +10,7 @@ dap.listeners.after.event_exited["dapui_config"] = function() dapui.close() end
local dotnet = require("dap.dap-dotnet") local dotnet = require("dap.dap-dotnet")
local odoo = require("dap.dap-odoo") local odoo = require("dap.dap-odoo")
local haskell = require("dap.dap-haskell") local haskell = require("dap.dap-haskell")
local go = require("dap.dap-go")
vim.keymap.set("n", "<leader>5", function() vim.keymap.set("n", "<leader>5", function()
@@ -39,7 +40,13 @@ vim.keymap.set("n", "<leader>b", function() dap.toggle_breakpoint() end)
vim.keymap.set("n", "<leader>B", function() dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) end) vim.keymap.set("n", "<leader>B", function() dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) end)
vim.keymap.set("n", "<leader>qd", function() dap.terminate() end) vim.keymap.set("n", "<leader>qd", function() dap.terminate() end)
vim.keymap.set("n", "<leader>rd", function() dap.restart() end) vim.keymap.set("n", "<leader>rd", function() dap.restart() end)
vim.keymap.set("n", "<leader>dt", odoo.run_odoo_test_at_cursor, { desc = "Debug Odoo Test unde Cursor" }) vim.keymap.set("n", "<leader>dt", function()
if vim.bo.filetype == "go" then
go.debug_test_at_cursor()
else
odoo.run_odoo_test_at_cursor()
end
end, { desc = "Debug Test under Cursor" })
dap.configurations.python = { dap.configurations.python = {
{ {
+115
View File
@@ -0,0 +1,115 @@
local dap = require("dap")
local M = {}
-- Locate the delve binary (prefer mason, fall back to PATH).
local function dlv_command()
local mason = vim.fn.expand("$HOME/.local/share/nvim/mason/bin/dlv")
if vim.fn.filereadable(mason) == 1 then
return mason
end
return "dlv"
end
-- Adapter: run delve in DAP server mode on a free port.
dap.adapters.go = {
type = "server",
port = "${port}",
executable = {
command = dlv_command(),
args = { "dap", "-l", "127.0.0.1:${port}" },
},
}
-- Configurations
dap.configurations.go = {
{
type = "go",
request = "launch",
name = "Debug (current file)",
program = "${file}",
},
{
type = "go",
request = "launch",
name = "Debug package",
program = "${fileDirname}",
},
{
type = "go",
request = "launch",
name = "Debug package (with args)",
program = "${fileDirname}",
args = function()
local input = vim.fn.input("Args: ")
return vim.split(input, " ", { trimempty = true })
end,
},
{
type = "go",
request = "launch",
mode = "test",
name = "Debug test (current file)",
program = "${file}",
},
{
type = "go",
request = "launch",
mode = "test",
name = "Debug test (package)",
program = "${fileDirname}",
},
{
type = "go",
request = "attach",
mode = "local",
name = "Attach to process",
processId = require("dap.utils").pick_process,
},
}
-- Debug the test function under the cursor using delve's -test.run filter.
local function debug_test_at_cursor()
local ok, node = pcall(vim.treesitter.get_node)
if not ok or not node then
vim.notify("Tree-sitter parser not found. Ensure you are in a Go buffer.", vim.log.levels.ERROR)
return
end
local func_name = nil
local attempts = 0
while node do
if node:type() == "function_declaration" then
for child in node:iter_children() do
if child:type() == "identifier" then
func_name = vim.treesitter.get_node_text(child, 0)
break
end
end
break
end
node = node:parent()
attempts = attempts + 1
if attempts > 50 then
break
end
end
if not func_name then
vim.notify("Cursor is not inside a test function.", vim.log.levels.WARN)
return
end
dap.run({
type = "go",
request = "launch",
mode = "test",
name = "Debug test: " .. func_name,
program = "${fileDirname}",
args = { "-test.run", "^" .. func_name .. "$" },
})
end
M.debug_test_at_cursor = debug_test_at_cursor
return M