golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.87k stars 745 forks source link

Incorrect path reported during dlv gap compilation #3138

Closed lzap closed 8 months ago

lzap commented 8 months ago

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:

  1. Create a new project with cmd/xxx/main.go file
  2. Make sure it contains syntax error
  3. Run or debug the main file
  4. 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.

hyangah commented 8 months ago

Duplicate of #2622