Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

“Run without debugging” unable to run on macOs when used gomod. #3121

Closed
wzh90 opened this issue Mar 23, 2020 · 8 comments · Fixed by #3125
Closed

“Run without debugging” unable to run on macOs when used gomod. #3121

wzh90 opened this issue Mar 23, 2020 · 8 comments · Fixed by #3125

Comments

@wzh90
Copy link

wzh90 commented Mar 23, 2020

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

  • Run go version to get version of Go
    • go1.14
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.43.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.31.1
  • Run go env GOOS GOARCH to get the operating system and processor architecture details
    • darwin/amd64

Share the Go related settings you have added/edited

{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"git.enabled": false,
"window.zoomLevel": 0,
"workbench.iconTheme": "vscode-icons",
"editor.defaultFormatter": "ms-vscode.Go",
"go.autocompleteUnimportedPackages": true,
"extensions.ignoreRecommendations": false,
"go.docsTool": "gogetdoc",
"go.useLanguageServer": true
}

“Start debugging” can run ,but “Run without debugging” unable to run on macOs when used gomod.

log:
Verbose logs are written to:
/var/folders/5v/f083s3c147b8xhll1wng2_8m0000gq/T/vscode-go-debug.txt
InitializeRequest
InitializeResponse
Using GOPATH: /Users/fish/Documents/code/go_path
../../../../code/go_workspace/ro/main.go:5:2: package ro/local is not in GOROOT (/usr/local/go/src/ro/local)
Process exiting with code: 1
Sending TerminatedEvent as delve is closed
DisconnectRequest
DisconnectRequest to parent

My code:
p

Please check it.

@stamblerre
Copy link
Contributor

I was able to reproduce this issue with a minimal repro. My guess is that this is running explicitly in GOPATH mode. This needs investigation and a fix.

@hyangah
Copy link
Contributor

hyangah commented Mar 23, 2020

Can any of you share the minimal repro case including the go.mod file? .zip file is fine.

@stamblerre
Copy link
Contributor

Ah, this was my mistake - I thought that this command came from the Go extension, but it comes from the user's launch.json. I'm seeing flaky behavior - if I use the default configuration, it works fine, but if I create a default launch.json file, I see the error. I'm not sure how to see what command is being executed under the hood.

@hawkwzh: What is the contents of your launch.json?

I've attached the repro.
mod1.zip

@wzh90
Copy link
Author

wzh90 commented Mar 24, 2020

@stamblerre
Just create launch.json, nothing changed.
f
I think the default launch settings are different from the generatedlaunch.json

@hyangah
Copy link
Contributor

hyangah commented Mar 24, 2020

I think I know what's going on.

Bug 1: When Run Without Debugging is invoked, resolveDebugConfiguration in goDebugConfiguration.ts is called with the initial debugConfiguration object with "noDebug": true, but it is overwritten here and the noDebug info is lost. As a result, later, I observed the debug adapter runs the program with debugging enabled (i.e. run through dlv).

Bug 2: When the debug adapter receives the request with "noDebug": true, it invokes go run <currentFIle> where the currentFile is the absolute path to the test file. And, it runs this command from the root directory /, which means the main module doesn't exist. The go run command operates in GOPATH mode and fails. So in this case, we should make the go run command to run inside the module.

I will prepare a cl.

When launch.json doesn't exist,

hyangah added a commit to hyangah/vscode-go-old that referenced this issue Mar 24, 2020
Bug 1: when generating the default debug configuration
because there is no user-configured one, the extension
dropped noDebug field and caused the program to run with
debugging enabled. Fix it (goDebugConfiguration.ts)

Bug 2: when debug adapter receives noDebug request, it
runs the program with `go run` instead of invoking the
program through dlv. The `go run` will not work in modules
mode if the command runs outside the main module. Set
cwd accordingly.

Fixes microsoft#3121

TESTED=manually with the example attached in microsoft#3121
ramya-rao-a added a commit that referenced this issue Mar 25, 2020
…guration (#3125)

* debug: fix 'run without debugging'

Bug 1: when generating the default debug configuration
because there is no user-configured one, the extension
dropped noDebug field and caused the program to run with
debugging enabled. Fix it (goDebugConfiguration.ts)

Bug 2: when debug adapter receives noDebug request, it
runs the program with `go run` instead of invoking the
program through dlv. The `go run` will not work in modules
mode if the command runs outside the main module. Set
cwd accordingly.

Fixes #3121

TESTED=manually with the example attached in #3121

* Handle case when debugConfiguration doesnt exist

Co-authored-by: Ramya Achutha Rao <ramyar@microsoft.com>
@ramya-rao-a
Copy link
Contributor

The fix to this is available in the latest beta version of this extension. Please do try it out and share feedback

@wzh90
Copy link
Author

wzh90 commented Mar 26, 2020

@ramya-rao-a it's worked.
thanks.

@ramya-rao-a
Copy link
Contributor

The latest version of the extension has the fix to this issue

@vscodebot vscodebot bot locked and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants