From 6d3e43932267c52ce8491fbdc1385202c8cf36d6 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Tue, 22 Jun 2021 11:01:27 -0400 Subject: [PATCH] gopls/doc: add instructions for working with generic code Change-Id: Ib0e5e16042791d96ed0d71e900b006a2c536032a Reviewed-on: https://go-review.googlesource.com/c/tools/+/330031 Trust: Robert Findley Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Rebecca Stambler --- gopls/doc/advanced.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gopls/doc/advanced.md b/gopls/doc/advanced.md index 93c6b8fdac..dbaf21c33a 100644 --- a/gopls/doc/advanced.md +++ b/gopls/doc/advanced.md @@ -34,4 +34,32 @@ You can achieve this by adding the right version of `go` to your `PATH` (`export PATH=$HOME/go/bin:$PATH` on Unix systems) or by configuring your editor. +## Working with generic code + +Gopls has experimental support for generic Go, as defined by the type +parameters proposal ([golang/go#43651](https://golang.org/issues/43651)) and +type set addendum ([golang/go#45346](https://golang.org/issues/45346)). + +To enable this support, you need to build gopls with a version of Go that +supports type parameters: the +[dev.typeparams branch](https://github.com/golang/go/tree/dev.typeparams). This +can be done by checking out this branch in the Go repository, or by using +`golang.org/dl/gotip`: + +``` +$ go get golang.org/dl/gotip +$ gotip download dev.typeparams +``` + +For building gopls with type parameter support, it is recommended that you +build gopls at tip. External APIs are under active development on the +`dev.typeparams` branch, so building gopls at tip minimizes the chances of +a build failure (though it is still possible). To get enhanced gopls features +for generic code, build gopls with the `typeparams` build constraint (though +this increases your chances of a build failure). + +``` +$ GO111MODULE=on gotip get -tags=typeparams golang.org/x/tools/gopls@master golang.org/x/tools@master +``` + [Go project]: https://go.googlesource.com/go