-
-
Notifications
You must be signed in to change notification settings - Fork 44
DAP support go
Zeioth edited this page Aug 26, 2023
·
8 revisions
Nothing special needs to be done for Go.
Please note that this section has nothing to do with compiler.nvim. I'm documenting this to make your life easier. To debug Go with DAP you have to:
- Install the mason package
delve. - Have initialized your module with
go mod init module_name. -
:cdyour project before running DAP.
Here you have an example of how to configure DAP for go
local dap = require("dap")
-- Go
-- Requires:
-- * You have initialized your module with 'go mod init module_name'.
-- * You :cd your project before running DAP.
dap.adapters.delve = {
type = 'server',
port = '${port}',
executable = {
command = vim.fn.stdpath('data')..'/mason/packages/delve/dlv',
args = {'dap', '-l', '127.0.0.1:${port}'},
}
}
dap.configurations.go = {
{
type = "delve",
name = "Compile module and debug this file",
request = "launch",
program = "./${relativeFileDirname}",
},
{
type = "delve",
name = "Compile module and debug this file (test)",
request = "launch",
mode = "test",
program = "./${relativeFileDirname}"
},
}Just insert a breakpoint, run :DapContinue and you will see something like

Congratulations, now you can compile and debug Go.
- You don't need any mason package.
- You don't need any plugin.
- You don't need to manually compile the program in debug mode before calling
DAP.dlvdo it automatically for you. - If you find any issue while configuring DAP, run
:DapSetLogLevel traceand:DapShowLogto find the reason.