golang / vscode-go

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

debug: can't specify a go package as 'program' if it is outside of the workspace #1115

Open rodrigovsilva opened 3 years ago

rodrigovsilva commented 3 years ago

Please direct general questions to:

Please review the documentation before filing an issue. Helpful pages include:

Please answer these questions before submitting your issue. Thanks!

What version of Go, VS Code & VS Code Go extension are you using?

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.

    "workbench.startupEditor": "newUntitledFile",
    "git.autofetch": true,
    "git.confirmSync": false,
    "git.enableSmartCommit": true,
    "explorer.confirmDelete": false,
    "window.zoomLevel": 0,
    "files.insertFinalNewline": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "go.lintTool": "golangci-lint",
    "go.lintFlags": [
        "--config=${workspaceFolder}/.golangci.yml",
        "--fast"
    ],
    "go.useLanguageServer": true,
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
        // Optional: Disable snippets, as they conflict with completion ranking.
        "editor.snippetSuggestions": "none",
    },
    "gopls": {
      // Add parameter placeholders when completing a function.
      "usePlaceholders": false,
      // If true, enable additional analyses with staticcheck.
      // Warning: This will significantly increase memory usage.
      "staticcheck": false,
    },
    "workbench.colorTheme": "Default Light+",
    // "go.testFlags": ["-test.v"]
    "go.languageServerFlags": [
        "-rpc.trace"
      ]
}

Describe the bug

I got an error when I try to debug my project

Steps to reproduce the behavior:

Trying to debug my application using launch.json

[10:44:25.244 UTC] From client: initialize({"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"go","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us","supportsProgressReporting":true,"supportsInvalidatedEvent":true})
[10:44:25.244 UTC] InitializeRequest
[10:44:25.244 UTC] To client: {"seq":0,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsSetVariable":true}}
[10:44:25.244 UTC] InitializeResponse
[10:44:25.244 UTC] From client: launch({"name":"location-service","type":"go","request":"launch","mode":"debug","logOutput":"rpc","trace":"verbose","showLog":true,"program":"/Users/rodrigo/go/src/mytest/cmd/test-service","env":{"ELECTRON_RUN_AS_NODE":"1","NVM_INC":"/Users/rodrigo/.nvm/versions/node/v11.15.0/include/node","TERM_PROGRAM":"Apple_Terminal","NVM_CD_FLAGS":"-q","TERM":"xterm-256color","SHELL":"/bin/zsh","TMPDIR":"/var/folders/x1/tbz0h40n64xd3c582x99b92w0000gn/T/","TERM_PROGRAM_VERSION":"440","TERM_SESSION_ID":"7AA87C44-0E06-4BE8-A6D0-A5E18D446495","NVM_DIR":"/Users/rodrigo/.nvm","USER":"rodrigo","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.J9scd2ui6k/Listeners","PATH":"/usr/local/go/bin:/usr/local/opt/openjdk/bin:/Users/rodrigo/.nvm/versions/node/v11.15.0/bin:/usr/local/opt/openjdk@11/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/rodrigo/go/bin:/Users/rodrigo/go/bin:/Users/rodrigo/bin","LaunchInstanceID":"DADBF9BB-4048-44B5-997C-DA1DD989C0B3","__CFBundleIdentifier":"com.apple.Terminal","PWD":"/Users/rodrigo/go/src/febo","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"0","HOME":"/Users/rodrigo","SHLVL":"2","GOROOT":"/usr/local/go","LOGNAME":"rodrigo","LC_CTYPE":"UTF-8","NVM_BIN":"/Users/rodrigo/.nvm/versions/node/v11.15.0/bin","GOPATH":"/Users/rodrigo/go","SECURITYSESSIONID":"186a7","_":"/Applications/Visual Studio Code.app/Contents/MacOS/Electron","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x0","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"true","VSCODE_CLI":"1","ELECTRON_NO_ATTACH_CONSOLE":"1","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","VSCODE_NLS_CONFIG":"{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_NODE_CACHED_DATA_DIR":"/Users/rodrigo/Library/Application Support/Code/CachedData/ea3859d4ba2f3e577a159bc91e3074c5d85c0523","VSCODE_IPC_HOOK":"/Users/rodrigo/Library/Application Support/Code/1.52.1-main.sock","VSCODE_PID":"90910","AMD_ENTRYPOINT":"vs/workbench/services/extensions/node/extensionHostProcess","PIPE_LOGGING":"true","VERBOSE_LOGGING":"true","VSCODE_IPC_HOOK_EXTHOST":"/var/folders/x1/tbz0h40n64xd3c582x99b92w0000gn/T/vscode-ipc-1d9d9321-e18e-42b4-aba3-054e41d03e0f.sock","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_LOG_STACK":"false","GOPROXY":"https://proxy.golang.org,direct","GRPC_ADDR":":10002","FLEETBIRD_SERVICE_ADDR":"localhost:10001"},"__configurationTarget":5,"packagePathToGoModPathMap":{},"apiVersion":2,"dlvLoadConfig":{"followPointers":true,"maxVariableRecurse":1,"maxStringLen":64,"maxArrayValues":64,"maxStructFields":-1},"showGlobalVariables":false,"dlvToolPath":"/Users/rodrigo/go/bin/dlv","__sessionId":"93440cd0-2a1a-4c92-80cc-661eb5f50d2a"})
[10:44:25.244 UTC] LaunchRequest
[10:44:25.253 UTC] Using GOPATH: /Users/rodrigo/go
[10:44:25.253 UTC] Using GOROOT: /usr/local/go
[10:44:25.253 UTC] Using PATH: /usr/local/go/bin:/usr/local/opt/openjdk/bin:/Users/rodrigo/.nvm/versions/node/v11.15.0/bin:/usr/local/opt/openjdk@11/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/rodrigo/go/bin:/Users/rodrigo/go/bin:/Users/rodrigo/bin
[10:44:25.253 UTC]   export NVM_INC="/Users/rodrigo/.nvm/versions/node/v11.15.0/include/node"
[10:44:25.253 UTC]   export TERM_PROGRAM="Apple_Terminal"
[10:44:25.253 UTC]   export NVM_CD_FLAGS="-q"
[10:44:25.253 UTC]   export TERM="xterm-256color"
[10:44:25.253 UTC]   export SHELL="/bin/zsh"
[10:44:25.253 UTC]   export TMPDIR="/var/folders/x1/tbz0h40n64xd3c582x99b92w0000gn/T/"
[10:44:25.253 UTC]   export TERM_PROGRAM_VERSION="440"
[10:44:25.253 UTC]   export TERM_SESSION_ID="7AA87C44-0E06-4BE8-A6D0-A5E18D446495"
[10:44:25.253 UTC]   export NVM_DIR="/Users/rodrigo/.nvm"
[10:44:25.253 UTC]   export USER="rodrigo"
[10:44:25.253 UTC]   export SSH_AUTH_SOCK="/private/tmp/com.apple.launchd.J9scd2ui6k/Listeners"
[10:44:25.253 UTC]   export PATH="/usr/local/go/bin:/usr/local/opt/openjdk/bin:/Users/rodrigo/.nvm/versions/node/v11.15.0/bin:/usr/local/opt/openjdk@11/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/rodrigo/go/bin:/Users/rodrigo/go/bin:/Users/rodrigo/bin"
[10:44:25.253 UTC]   export LaunchInstanceID="DADBF9BB-4048-44B5-997C-DA1DD989C0B3"
[10:44:25.253 UTC]   export __CFBundleIdentifier="com.apple.Terminal"
[10:44:25.253 UTC]   export PWD="/Users/rodrigo/go/src/febo"
[10:44:25.254 UTC]   export XPC_FLAGS="0x0"
[10:44:25.254 UTC]   export XPC_SERVICE_NAME="0"
[10:44:25.254 UTC]   export HOME="/Users/rodrigo"
[10:44:25.254 UTC]   export SHLVL="2"
[10:44:25.254 UTC]   export GOROOT="/usr/local/go"
[10:44:25.254 UTC]   export LOGNAME="rodrigo"
[10:44:25.254 UTC]   export LC_CTYPE="UTF-8"
[10:44:25.254 UTC]   export NVM_BIN="/Users/rodrigo/.nvm/versions/node/v11.15.0/bin"
[10:44:25.254 UTC]   export GOPATH="/Users/rodrigo/go"
[10:44:25.254 UTC]   export SECURITYSESSIONID="186a7"
[10:44:25.254 UTC]   export _="/Applications/Visual Studio Code.app/Contents/MacOS/Electron"
[10:44:25.254 UTC]   export __CF_USER_TEXT_ENCODING="0x1F5:0x0:0x0"
[10:44:25.254 UTC]   export APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL="true"
[10:44:25.254 UTC]   export VSCODE_CLI="1"
[10:44:25.254 UTC]   export ELECTRON_NO_ATTACH_CONSOLE="1"
[10:44:25.254 UTC]   export ORIGINAL_XDG_CURRENT_DESKTOP="undefined"
[10:44:25.254 UTC]   export VSCODE_NLS_CONFIG="{"locale":"en-us","availableLanguages":{},"_languagePackSupport":true}"
[10:44:25.254 UTC]   export VSCODE_NODE_CACHED_DATA_DIR="/Users/rodrigo/Library/Application Support/Code/CachedData/ea3859d4ba2f3e577a159bc91e3074c5d85c0523"
[10:44:25.254 UTC]   export VSCODE_IPC_HOOK="/Users/rodrigo/Library/Application Support/Code/1.52.1-main.sock"
[10:44:25.254 UTC]   export VSCODE_PID="90910"
[10:44:25.254 UTC]   export AMD_ENTRYPOINT="vs/workbench/services/extensions/node/extensionHostProcess"
[10:44:25.254 UTC]   export PIPE_LOGGING="true"
[10:44:25.254 UTC]   export VERBOSE_LOGGING="true"
[10:44:25.254 UTC]   export VSCODE_IPC_HOOK_EXTHOST="/var/folders/x1/tbz0h40n64xd3c582x99b92w0000gn/T/vscode-ipc-1d9d9321-e18e-42b4-aba3-054e41d03e0f.sock"
[10:44:25.254 UTC]   export VSCODE_HANDLES_UNCAUGHT_ERRORS="true"
[10:44:25.254 UTC]   export VSCODE_LOG_STACK="false"
[10:44:25.254 UTC]   export GOPROXY="https://proxy.golang.org,direct"
[10:44:25.254 UTC]   export ELECTRON_RUN_AS_NODE="1"
[10:44:25.254 UTC]   export GRPC_ADDR=":10002"
[10:44:25.254 UTC]   export FLEETBIRD_SERVICE_ADDR="localhost:10001"
[10:44:25.254 UTC] Current working directory: /Users/rodrigo/go/src/mytest/cmd/test-service
[10:44:25.254 UTC] Running: /Users/rodrigo/go/bin/dlv debug mytest/cmd/test-service --headless=true --listen=127.0.0.1:16566 --api-version=2 --log=true --log-output=rpc
[10:44:25.325 UTC] To client: {"seq":0,"type":"event","event":"output","body":{"category":"stderr","output":"can't load package: package mytest/cmd/test-service is not in GOROOT (/usr/local/go/src/mytest/cmd/test-service)\n"}}
[10:44:25.327 UTC] To client: {"seq":0,"type":"event","event":"output","body":{"category":"stderr","output":"exit status 1\n"}}
[10:44:25.328 UTC] [Error] Process exiting with code: 1
[10:44:25.328 UTC] To client: {"seq":0,"type":"response","request_seq":2,"command":"launch","success":false,"message":"Failed to continue: Check the debug console for details.","body":{"error":{"id":3000,"format":"Failed to continue: Check the debug console for details.","showUser":true}}}
[10:44:25.328 UTC] Sending TerminatedEvent as delve is closed
[10:44:25.328 UTC] To client: {"seq":0,"type":"event","event":"terminated"}
[10:44:25.354 UTC] From client: disconnect({"restart":false})
[10:44:25.354 UTC] DisconnectRequest
[10:44:25.354 UTC] Closing Delve.
[10:44:25.355 UTC] HaltRequest
[10:44:26.358 UTC] Killing debug process manually as we could not halt delve in time
[10:44:26.358 UTC] killing debugee (pid: 91161)...
[10:44:26.359 UTC] DisconnectRequest to parent to shut down protocol server.
[10:44:26.359 UTC] To client: {"seq":0,"type":"response","request_seq":3,"command":"disconnect","success":true}
[10:44:26.359 UTC] DisconnectResponse
hyangah commented 3 years ago

@rodrigovsilva Thanks for the report. It looks like the current workspace root and pwd is ~/go/src/febo (in module mode, because there is go.mod file) and you want to debug ~/go/src/mytest/cmd/test-service which is outside of your main module (~/go/src/febo). I am afraid the debug adapter handles such case correctly. A couple of things to try (I am not sure if these will work yet):

@suzmue @polinasok The relevant code path doesn't seem to handle this use case. From the user's report, I see

PWD: "/Users/rodrigo/go/src/febo"

and the launch request (mode: debug) has

"packagePathToGoModPathMap":{}
"program":"/Users/rodrigo/go/src/mytest/cmd/test-service",

The code path seems problematic for many reasons - i.e., it assumes the current Go workspace based on the GOPATH, which is no longer true in the module mode.