2

My vscode does not detect errors in golang.

Example:

package somepackage

import "fmt"

func f(name string) string {
    name = 1
    return name
}

This should throw a type error, but it does not. I never get any errors.

My settings.json contains

"go.gopath": "some/path", 
"go.vetOnSave": "package",
"go.lintOnSave": "package",
"go.testOnSave": true,
"go.buildOnSave": "package",
"go.coverOnSave": true 

I was able to run go: install/update Tools. All tools are installed successfully.

I am also able to run debug a .go file in vscode.

3
  • 1
    Is your GOROOT path set? Also are there any other go files in the same project where there might an error? Commented Apr 9, 2019 at 0:52
  • Yes, I inserted go.goroot in my application. Apparently, I have two conflicting go installations on my computer. After recompiling the tools, vscode was able to detect errors. Thanks! Please submit your suggestion as an answer so I can close this issue. Commented Apr 9, 2019 at 6:49
  • I keep seeing "go: install/update tools" in documentation. Has this option been removed recently? I'm assuming it was an old menu setting Go > Install/update tools? Commented May 29, 2020 at 17:00

1 Answer 1

7

As @pwaterz pointed out, the solution to my problem was to add "go.goroot: /some/other/path".

The reason that vscode was not able to detect errors was, that there are different go versions on my computer. Adding the goroot and running go: install/update Tools solved the problem.

---- Edit: Multiple go versions ----

Had multiple conflicting go versions on my Mac, pulled in via brew. Fixed the problem with a reinstall.

  • Uninstall go and also run brew uninstall go
  • Reinstall go
  • Set environment variables in your .bash_profile or similar. Compare here.
  • Apply the changes to your profile by running e.g. source .bash_profile
  • Restart VSCode
  • In settings.json set "go.goroot": "/usr/local/go"
  • Run go: Toggle workspace trust space to make sure changes to settings.json are applied (you have to trust your workspace for that)
  • go: Install/update tools and select all

---- Edit: Incorrect root folder ----

Make sure that you open the root folder of your project and not a sub-folder of your project. That may cause in invalid import paths otherwise

---- Edit: Broken language server ----

Sign up to request clarification or add additional context in comments.

2 Comments

I had this problem again. Be aware that you may need to Go: Toggle Workspace Trust Flag before running go: install/update Tools. Otherwise the change to go.goroot will be ignored.
Nice, running Go: Install/Update tools from the command palette worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.