x/tools/gopls: working with the go2go generics prototype
Closed this issue · 1 comments
For full context, see https://blog.golang.org/generics-next-step.
gopls can be made to work with the generics prototype. It will work with any editor that recognizes .go2 as a Go file extension.
As of 06/16/2020, the only way to do this is by installing a special version of the VS Code Go extension. This issue will be updated as other editors begin to support this.
Follow these instructions to build and use gopls with the dev.go2go branch of Go.
Build go
First, build Go at this branch from source:
git clone https://go.googlesource.com/go
cd go
git checkout dev.go2go
(cd src && ./make.bash)Make sure that this version of go is first on your PATH. Confirm by running go version.
Next, using that version of go, install the dev.go2go-compatible version of gopls:
Build gopls
GO111MODULE=on go get golang.org/x/tools/gopls@dev.go2go golang.org/x/tools@dev.go2goInstall a go2-version of the VS Code Go extension
The final step will be to configure your editor to recognize .go2 files. You can do this by installing a special version of the VS Code Go extension that can translate between .go and .go2 files.
This extension is distributed as a .vsix file and can be found in the dev.go2go VS Code Go release. Download go-nightly-0.0.0.vsix and manually install the extension by following these steps:
- Open a VS Code window and navigate to the Extensions View.
- Disable or uninstall the default Go extension. Note: You will need to undo this when you want to return to your normal development flow.
- Click on the "..." in the top-right corner, select "Install from VSIX...", and choose
go-nightly-0.0.0.vsix. Alternatively, you can run code --install-extension path/to/go.vsix or open the Command Palette and run the Extensions: Install from VSIX... command.
Troubleshooting
If it's not working, make sure that your version of Go in VS Code is the dev.go2go version you built.
You can check the version in the gopls (server) output logs (View: Toggle Output -> Tasks -> gopls (server)).
You can also explicitly specify the path to the go version in your settings.json file:
"go.alternateTools": {
"go": "/path/to/go/bin/go"
}Closing this in favor of the new instructions: https://github.com/golang/tools/blob/master/gopls/doc/advanced.md#working-with-generic-code.