Repository: golang/vscode-go

Issue #2622: Filenames in launch output build errors are not clickable
Created: 2023-01-20T21:16:54Z
What version of Go, VS Code & VS Code Go extension are you using?
Version Information

Run go version to get version of Go from the VS Code integrated terminal.

go version go1.19.2 linux/amd64


Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

golang.org/x/tools/gopls v0.11.0


Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

1.74.3 97dec172d3256f8ca4bfb2143f3f76b503ca0534


Check your installed extensions to get the version of the VS Code Go extension

v0.37.1


Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

gotests:	not installed
gomodifytags:	not installed
impl:	not installed
goplay:	not installed
dlv:	/go/bin/dlv	(version: v1.20.1 built with go: go1.19.2)
golangci-lint:	/go/bin/golangci-lint	(version: v1.50.1 built with go: go1.19.2)
gopls:	/go/bin/gopls	(version: v0.11.0 built with go: go1.19.2)


Describe the bug
When starting a debug session fails due to go build errors, VS Code can't open the file paths printed.
This is because the paths are relative to the built package, and not the workspace root as VS Code expects.
Steps to reproduce the behavior:

Add a Go launch configuration
Break compilation
Launch a debug session
Ctrl-Click a path in the go build output

Duplicate issue #3138: Incorrect path reported during dlv gap compilation
Created: 2024-01-17T07:51:26Z
What version of Go, VS Code & VS Code Go extension are you using?
Version Information


Run go version to get version of Go from the VS Code integrated terminal.

go version go1.21.4 linux/amd64



Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

golang.org/x/tools/gopls v0.14.2



Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

1.85.1



Check your installed extensions to get the version of the VS Code Go extension

v0.40.1



Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /home/lzap/go
GOROOT: /usr/lib/golang
PATH: /home/lzap/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/bin/remote-cli:/home/lzap/.rbenv/shims:/home/lzap/.rbenv/bin:/Mutt:/home/lzap/.local/bin:/home/lzap/bin:/home/lzap/bin/public:/home/lzap/.npm/bin:/home/lzap/go/bin:/home/lzap/.rbenv/shims:/home/lzap/.rbenv/bin:/Mutt:/home/lzap/.local/bin:/home/lzap/bin:/home/lzap/bin/public:/home/lzap/.npm/bin:/home/lzap/go/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/work/foreman-bats:/home/lzap/.fzf/bin:/work/foreman-bats

go:	/usr/bin/go: go version go1.21.4 linux/amd64
gopls:	/home/lzap/go/bin/gopls	(version: v0.14.2 built with go: go1.21.4)
gotests:	/home/lzap/go/bin/gotests	(version: v1.6.0 built with go: go1.21.4)
gomodifytags:	/home/lzap/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.21.4)
impl:	/home/lzap/go/bin/impl	(version: v1.1.0 built with go: go1.21.4)
goplay:	/home/lzap/go/bin/goplay	(version: v1.0.0 built with go: go1.21.4)
dlv:	/home/lzap/go/bin/dlv	(version: v1.22.0 built with go: go1.21.4)
staticcheck:	/home/lzap/go/bin/staticcheck	(version: v0.4.6 built with go: go1.21.4)


go env
Workspace Folder (forester): /home/lzap/work/forester
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/lzap/.cache/go-build'
GOENV='/home/lzap/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/lzap/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/lzap/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/usr/lib/golang'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/lzap/work/forester/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4049107857=/tmp/go-build -gno-record-gcc-switches'

Share the Go related settings you have added/edited
Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.
    "go.toolsManagement.autoUpdate": true,

Describe the bug
When a main package is in a project subdirectory, for example cli/xxx and a debug session is started, go compiler spawned by dlv reports incorrect paths:
Starting: /home/lzap/go/bin/dlv dap --listen=127.0.0.1:45903 --log-dest=3 from /home/lzap/work/forester/cmd/controller
DAP server listening at: 127.0.0.1:45903
Build Error: go build -o /home/lzap/work/forester/cmd/controller/__debug_bin4218768791 -gcflags all=-N -l ./ctl_main.go
# forester/internal/api/ctl
../../internal/api/ctl/common.go:68:7: invalid case model.RedfishManualApplianceKind in switch on kind (mismatched types model.ApplianceKind and int16) (exit status 1)

The link ../../internal/api/ctl/common.go:68:7, when clicked, leads to nowhere because VSCode expects file path relative to the project root, not to the directory where dlv was started.
Steps to reproduce the behavior:

Create a new project with cmd/xxx/main.go file
Make sure it contains syntax error
Run or debug the main file
Click (control/command) on the file path reported by go compiler.

Screenshots or recordings
My run configuration:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Controller",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "cmd/controller/ctl_main.go",
            "cwd": "${workspaceFolder}"
        }
    ]
}

It is worth mentioning that current working directory is set correctly (project root), the problem is during compilation phase. It is executed in ${workspaceFolder}/cmd/controller and therefore file paths in errors from dlv/go compiler are not interpreted correctly. There is no way to set delve/vscode in a way this works at the moment. Thanks.

Closing comment (2024-01-17T19:36:08Z): Duplicate of #2622