Recently I have updated go debugger to dlv-dap and now I have problems debugging go packages. This is my file structure:
File contents:
main.go
package main
import (
"debugger_test/packageA"
"fmt"
)
func main() {
res := packageA.DoStuff(5)
fmt.Println(res)
}
fileA.go
package packageA
func DoStuff(a int) int {
temp := a*a - 30
return temp
}
fileA_test.go
package packageA
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStuff(t *testing.T) {
arg := 2
res := DoStuff(arg)
assert.Equal(t, -26, res)
}
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "Test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"substitutePath": [
{
"from": "/home/vlasov",
"to": "/opt/storage",
},
],
},
{
"name": "Main",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}",
"substitutePath": [
{
"from": "/home/vlasov",
"to": "/opt/storage",
},
],
}
]
}
This used to work just fine before dlv-dap. Now when I try to debug I get this message:
Starting: /home/vlasov/go/bin/dlv-dap dap --listen=127.0.0.1:46369 --log-dest=3
DAP server listening at: 127.0.0.1:46369
Build Error: go test -c -o /opt/storage/debugger_test/packageA/__debug_bin -gcflags all=-N -l /home/vlasov/debugger_test/packageA
directory /home/vlasov/debugger_test/packageA outside available modules (exit status 1)
A partial fix I was able to find is to change ${fileDirname} to ${fileDirname}/main.go, however this way debugger does not hit breakpoints in main.go. This method does not work for tests, I still get similar message with "program": "${fileDirname}/fileA_test.go".
What is the correct way to configure launch.json to be able to run debug tests and packages normally?
