-
-
Notifications
You must be signed in to change notification settings - Fork 44
DAP support go
Zeioth edited this page Aug 9, 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:
- Have the system dependency
dlv. - 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 the system dependency 'dlv'.
-- * You have initialized your module with 'go mod init module_name'.
-- * You :cd your project before running DAP.
-- note that no mason package or nvim plugin is required.
dap.adapters.delve = {
type = 'server',
port = '${port}',
executable = {
command = '/usr/bin/dlv', -- Ensure this is correct
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 before calling
DAP.dlvwill do it automatically for you. - If you find any issue while configuring DAP, run
:DapSetLogLevel traceand:DapShowLogto find the reason.