0

I can't run the go program on vscode on my Win11 computer (no run button, pressing Ctrl+F5 or F5 doesn't work,like this: vscode ) and I can't debug it. It's not written on FAQ.

It works on my other Win10 PC. All dependencies are installed

This is my settings.json:

    "go.autocompleteUnimportedPackages": true,
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.inferGopath": false,
    "go.gopath": "F:\\vscodefiles\\src\\hello",
    "go.goroot": "D:\\go\\",
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,

why is this?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Zhang Yichi
  • 39
  • 1
  • 5
  • 2
    What do you mean by "pressing Ctrl+F5 or F5 doesn't work"? Do you see any error message? Run button should be visible from the "Run and Debug" view (if you don't see the view, find "View: Show Run And Debug" command from the command palette). – Hana Apr 17 '22 at 18:21

2 Answers2

0

Besides installing Go locally, for VSCode you need to install the correct extension:

https://marketplace.visualstudio.com/items?itemName=golang.Go

You can install this extension by navigating to "Extensions" with:

Windows: ctrl + shift + x

MacOS: command + shift + x

Then searching for "go" which is by author "Go Team at Google"

When you navigate back to your code, you can now press F5 to trigger a debugging run.


Note when pressing F5 pay attention to the bottom right as you may be prompted to install further dependencies (I had to install 3 more)

I also needed to execute this in a terminal as I kept seeing "no go.mod detected in the current directory"

go env -w GO111MODULE=off

as per this answer

Ari
  • 745
  • 1
  • 7
  • 23
-1

Try in the terminal:

go run myfirstprogram.go

enter image description here

Remember to install Go on your computer before, you can download it from its official page: https://go.dev/ and restart Visual Studio Code.

Nube Colectiva
  • 147
  • 2
  • 7