Reputation: 8447
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.
Upvotes: 2
Views: 8382
Reputation: 8447
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.
brew uninstall go
.bash_profile
or similar. Compare here.source .bash_profile
settings.json
set "go.goroot": "/usr/local/go"
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 ----
go: restart language server
go mod tidy
and try againUpvotes: 6