-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
. -
:cd
your 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}"
},
}
You don't need to manually compile the program before calling DAP
. dlv
will do it automatically.
Congratulations, now you can compile and debug Go.
- You don't need any mason package.
- You don't need any plugin.
- If you find any issue while configuring DAP, run
:DapSetLogLevel trace
and:DapShowLog
to find the reason.