mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.46k stars 194 forks source link

cwd in .vscode/launch.json seems to be ignored #1105

Closed steventhorne closed 10 months ago

steventhorne commented 10 months ago

Debug adapter definition and debug configuration

launch.json:

"configurations": [
  {
    "name": "Launch server",
    "type": "go",
    "request": "launch",
    "cwd": "${workspaceFolder}/src",
    "program": "${workspaceFolder}/cmd/server"
  },
  {
    "name": "Attach to Process",
    "type": "go",
    "request": "attach",
    "mode": "local"
  }
]

Debug adapter version

0.7.0

Steps to Reproduce

In a go project with the mod file in a subdirectory, the delve adapter will not be able to find the mod file because the command is run from the ${workspaceFolder} instead of the path specified in cwd. I need to be able to specify the cwd property so that it can find the mod file correctly.

Expected Result

The delve adapter runs from the folder specified in cwd.

Log output:

Build Error: go build -o USERPATH\Documents\Projects\goproject\__debug_bin4053846197.exe -gcflags all=-N -l USERPATH\Documents\Projects\goproject/cmd/server
go: cannot find main module, but found .git/config in USERPATH\Documents\Projects\goproject
  to create a module there, run:
  go mod init (exit status 1)

Actual Result

The delve adapter runs from the ${workspaceFolder} instead.

mfussenegger commented 10 months ago

Maybe you need to use dlvCwd. See https://github.com/go-delve/delve/blob/master/Documentation/api/dap/README.md

nvim-dap has no special treatment for the configuration options and passes through all of them. You can verify that by enabling trace logging and looking for the launch request.