How to set the version of gopls to install with vscode Go extension?

2.2k Views Asked by At

I'm running go1.16, the latest gopls version is not compabtible with it. Confirmed it at https://github.com/golang/tools/blob/master/gopls/README.md. The installation fails with below error

Installing golang.org/x/tools/gopls@latest FAILED
{
 "code": 1,
 "killed": false,
 "signal": null,
 "cmd": "/usr/local/bin/go install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "go: downloading golang.org/x/tools v0.12.0\ngo/pkg/mod/golang.org/x/tools/[email protected]/internal/lsp/source/options.go:25:2: //go:build comment without // +build comment\n"
}

1 tools failed to install.

I want to use vscode to install a version that is compatible, for example v0.12.4.

I can get it to work by manually installing it, is there a way to configure the version for gopls in vscode ?

2

There are 2 best solutions below

1
ntutm0922 On

Currently(at least under my comprehension), if you want to rollback to specific version of any vscode extension, you can go to the extension page and click the dropdown to find Install another version. Extension Go in extension page

0
Balakumar Subramani On

At the moment, there is no option to configure tool versions in vscode-go. It blindly picks the latest version available for gopls. A version is not set here or here.

Only option is to manually install a lower version. Highest gopls version that work with go1.16 is v0.12.4, install it with below command,

go install golang.org/x/tools/[email protected]

And disable check for updates with below setting. The extension currently check updates only for gopls.

"go.toolsManagement.checkForUpdates": "off"