Open nnarayen opened 1 year ago
I am not a user of nvim-dap-go
, but came across this issue with custom nvim-dap config.
For me I use substitutePath
with vscode launch.json
, that works pretty well, maybe you can try using that.
``` { "version": "0.2.0", "configurations": [ { "name": "Golang: Remote Attach delve launch.json", "type": "go", "debugAdapter": "dlv-dap", "request": "attach", "mode": "remote", "preLaunchTask": "debug-attach", "postDebugTask": "debug-stop", "connect": { "host": "127.0.0.1", "port": 38697 }, "logToFile": true, "cwd": "${workspaceFolder}", "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/app" } ], "substitutePath": [{ "from": "${workspaceFolder}", "to": "/app" }] } ] } ```
Unfortunately, I haven't found a way to have the nvim dap client perform any path substitutions.
@nnarayen I am also unaware of such configuration. Have you tried asking in the nvim-dap project?
I was able to set the substitutionPath
from configurations as described at https://github.com/mfussenegger/nvim-dap/issues/905.
It requires some ingenuity as the substitutePath
needs to match the remote path, but I have been able to debug applications running on Docker with the configuration below.
local dap_go = require('dap-go')
local dap = require('dap')
dap_go.setup()
table.insert(dap.configurations.go, {
type = 'delve',
name = 'Attach remote',
mode = 'remote',
request = 'attach',
substitutePath = {
{ from = '${workspaceFolder}', to = '/app' },
},
})
dap.adapters.delve = {
type = 'server',
host = 'localhost',
port = '38697'
}
It works like this.
@nnarayen can you please try the suggestion provided by @ryutah and confirm that it is working for you. Maybe we can improve the docs describing it for users with the same requirements.
Hi, debug in remote container in Kubernetes works fine for me.
Here is the full plugin config for Lazy
.
{
"leoluz/nvim-dap-go",
opts = {
dap_configurations = {
{
-- Must be "go" or it will be ignored by the plugin
type = "go",
name = "Connect remote",
request = "attach",
mode = "remote",
substitutePath = {
{
from = "${workspaceFolder}",
to = "/app",
},
},
},
},
delve = {
port = 2345,
},
},
},
I use 2345 port for communication with dlv, so my command in remote container is
dlv debug --headless --listen=:2345 --log --api-version=2
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I can confirm that setup given from @ryutah works fine for me to debug in a remote container. In my case I use /wd
as my application path in docker, so I have to change it. This is my entirely setup:
Dockerfile:
FROM golang:1.20-bullseye
WORKDIR /wd
COPY go.mod .
COPY go.sum .
RUN go mod download -x
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY . .
CMD ["dlv", "debug", "--listen=:34567", "--headless", "--build-flags='-buildvcs=false'"]
nvim setup:
local dap_go = require('dap-go')
local dap = require('dap')
dap_go.setup()
table.insert(dap.configurations.go, {
type = 'delve',
name = 'Container debugging (/wd:34567)',
mode = 'remote',
request = 'attach',
substitutePath = {
{ from = '${workspaceFolder}', to = '/wd' },
},
})
dap.adapters.delve = {
type = 'server',
host = 'localhost',
port = '34567'
}
docker-compose:
version: '3'
services:
app:
container_name: my-app
hostname: my-app
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
- '34567:34567'
restart: unless-stopped
volumes:
- ./:/wd
I'm currently using
nvim-dap
andnvim-dap-go
to connect to a headlessdlv
server running remotely in k8s. Unfortunately, the source code during compilation of the remote binary is different than my local source code, so by default most breakpoint functionality does not work.As far as I understand, path transformations occur client side and not on the
dlv
server. I can get this to work viadlv connect
on my local machine either withconfig substitute-path <from> <to>
or via thedlv
config.yml file. Unfortunately, I haven't found a way to have the nvim dap client perform any path substitutions.This issue is more of an open question, but do you know if that's currently possible? Thanks in advance!
Build information
Remote
dlv
servernvim-dap
: v0.5.0nvim-dap-go
: shab4ded7de579b4e2a85c203388233b54bf1028816