Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: vscode fails to run the project if tab with name like "_test" is active #1422

Closed
schroding3rscat opened this issue Apr 14, 2021 · 6 comments
Assignees
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge
Milestone

Comments

@schroding3rscat
Copy link

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

  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.16.3 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.6.10
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.55.1
    • 08a217c4d27a02a5bcde898fd7981bda5b49391b
    • x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.24.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/axm/go
GOROOT: /usr/local/opt/go/libexec
PATH: /usr/local/opt/go/libexec/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/go/bin:/Users/axm/go/bin:/Users/axm/vscode/bin:/Users/axm/Library/Python/2.7/bin

   gopkgs: /Users/axm/go/bin/gopkgs installed
   go-outline: /Users/axm/go/bin/go-outline installed
   gotests: /Users/axm/go/bin/gotests installed
   gomodifytags: /Users/axm/go/bin/gomodifytags installed
   impl: /Users/axm/go/bin/impl installed
   goplay: /Users/axm/go/bin/goplay installed
   dlv: /Users/axm/go/bin/dlv installed
   dlv-dap: /Users/axm/go/bin/dlv-dap installed
   staticcheck: /Users/axm/go/bin/staticcheck installed
   gopls: /Users/axm/go/bin/gopls installed

go env
Workspace Folder (offer): /Users/axm/go/src/git.company.com/suppliers-portal/offer
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/Users/axm/Library/Caches/go-build"
	GOENV="/Users/axm/Library/Application Support/go/env"
	GOEXE=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/axm/go/pkg/mod"
	GONOPROXY="*.company.com"
	GONOSUMDB="*.company.com"
	GOOS="darwin"
	GOPATH="/Users/axm/go"
	GOPRIVATE="*.company.com"
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/usr/local/opt/go/libexec"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
	GOVCS=""
	GOVERSION="go1.16.3"
	GCCGO="gccgo"
	AR="ar"
	CC="clang"
	CXX="clang++"
	CGO_ENABLED="1"
	GOMOD="/Users/axm/go/src/git.company.com/suppliers-portal/offer/go.mod"
	CGO_CFLAGS="-g -O2"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-g -O2"
	CGO_FFLAGS="-g -O2"
	CGO_LDFLAGS="-g -O2"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2v/g6mnjfx50c9_8dgtttz0kks80000gn/T/go-build339879520=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

"go.useLanguageServer": true,
    "[go]": {
        "editor.insertSpaces": false,
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    "[go.mod]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
    },
    "gopls": {
        // Add parameter placeholders when completing a function.
        "usePlaceholders": true,
        // If true, enable additional analyses with staticcheck.
        // Warning: This will significantly increase memory usage.
        "staticcheck": false,
    },
"go.goroot": "/usr/local/go",
    "go.gopath": "~/go",
    "go.toolsManagement.autoUpdate": true,

Describe the bug

I configure all my projects to run from ${workspaceFolder}/cmd. Everything is OK until I try to press F5 when I have any *_test.go file as an active tab. When I do this, I see this error in the output:

could not launch process: open /Users/axm/go/src/git.company.com/portal/offer/cmd/offer/debug.test: no such file or directory
could not remove /Users/axm/go/src/git.company.com/portal/offer/cmd/offer/debug.test: remove /Users/axm/go/src/git.company.com/portal/offer/cmd/offer/debug.test: no such file or directory
Process exiting with code: 1

This issue won't reproduce when I set any other non-test file as active tab.

My launch.json:

"version": "0.2.0",
    "configurations": [
        {
            "name": "Launch service",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/cmd/offer/main.go",
            "env": {
                "DEBUG": true,
                "MAX_CACHE_SIZE_MB": "128"
            },
            "args": []
        }
    ]

Steps to reproduce the behavior:

  1. Clone test project https://github.com/schroding3rscat/vscode-go-bug-test
  2. Open cmd/someapp/main.go, set this tab as active
  3. Press F5
  4. Project runs OK
  5. Open pkg/somepackage/package_test.go, set this tab as active
  6. Project fails to run

Screenshots or recordings

image

@gopherbot gopherbot added this to the Untriaged milestone Apr 14, 2021
@hyangah hyangah added the Debug Issues related to the debugging functionality of the extension. label Apr 14, 2021
@hyangah hyangah changed the title vscode fails to run the project if tab with name like "_test" is active debug: vscode fails to run the project if tab with name like "_test" is active Apr 14, 2021
@hyangah
Copy link
Contributor

hyangah commented Apr 14, 2021

Thanks for reporting the issue. @schroding3rscat
Can you try "mode": "debug" instead of "mode": "auto"?

cc/ @suzmue @polinasok

@hyangah hyangah modified the milestones: Untriaged, On Deck, Backlog Apr 14, 2021
@schroding3rscat
Copy link
Author

schroding3rscat commented Apr 14, 2021

Can you try "mode": "debug" instead of "mode": "auto"?

"mode": "debug" helped, thanks. Is this an expected behavior? I'm certainly can configure this in all projects, but auto as the default value is confusing. Especially when I pass the non-test file in the program parameter.

@hyangah
Copy link
Contributor

hyangah commented Apr 14, 2021

Agree it's confusing.

Looking into the history, the '"auto"' mode was originated from microsoft/vscode-go#1780 and it seems that the intention was to switch the mode between 'test' and 'debug' based on the open file.

How about adjusting the logic like the following?

  • if program is a go file (.go), select debug and test depending on whether it is a non-test file or test file.
  • if program is a directory, select debug and test depending on whether the open file is a non-test file or test file.

Stretch - if the open file is not in a main package, consider to switch to test mode. (related: #94)

@schroding3rscat
Copy link
Author

Sounds reasonable, will be great.

@hyangah hyangah added the NeedsFix The path to resolution is known, but the work has not been done. label May 3, 2021
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/316509 mentions this issue: src/goDebugConfiguration.ts: use program to determine mode if file

gopherbot pushed a commit that referenced this issue May 4, 2021
If the `program` attribute is a go file, then we can use this to
determine whether to run 'debug' or 'test'.

If the program for 'test' mode is a test file, we run it instead in
the package.

Updates #1422

Change-Id: I869b0cb7422634d74dee5a04f6cc131be17ddc2f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/316509
Trust: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
lggomez pushed a commit to lggomez/vscode-go-1 that referenced this issue May 6, 2021
If the `program` attribute is a go file, then we can use this to
determine whether to run 'debug' or 'test'.

If the program for 'test' mode is a test file, we run it instead in
the package.

Updates golang#1422

Change-Id: I869b0cb7422634d74dee5a04f6cc131be17ddc2f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/316509
Trust: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@suzmue suzmue modified the milestones: Backlog, v0.25.0 May 10, 2021
@hyangah
Copy link
Contributor

hyangah commented May 25, 2021

This was released in v0.25.0. Closing. Thanks @suzmue

@hyangah hyangah closed this as completed May 25, 2021
@polinasok polinasok removed the NeedsFix The path to resolution is known, but the work has not been done. label Jul 16, 2021
@golang golang locked and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

5 participants