golang.org/x/tools/gopls@v0.15.3/doc/advanced.md (about)

     1  # Advanced topics
     2  
     3  This documentation is for advanced `gopls` users, who may want to test
     4  unreleased versions or try out special features.
     5  
     6  ## Installing unreleased versions
     7  
     8  To get a specific version of `gopls` (for example, to test a prerelease
     9  version), run:
    10  
    11  ```sh
    12  GO111MODULE=on go install golang.org/x/tools/gopls@vX.Y.Z
    13  ```
    14  
    15  Where `vX.Y.Z` is the desired version.
    16  
    17  ### Unstable versions
    18  
    19  To update `gopls` to the latest **unstable** version, use the following
    20  commands.
    21  
    22  ```sh
    23  # Create an empty go.mod file, only for tracking requirements.
    24  cd $(mktemp -d)
    25  go mod init gopls-unstable
    26  
    27  # Use 'go get' to add requirements and to ensure they work together.
    28  go get -d golang.org/x/tools/gopls@master golang.org/x/tools@master
    29  
    30  go install golang.org/x/tools/gopls
    31  ```
    32  
    33  ## Working on the Go source distribution
    34  
    35  If you are working on the [Go project] itself, the `go` command that `gopls`
    36  invokes will have to correspond to the version of the source you are working
    37  on. That is, if you have checked out the Go project to `$HOME/go`, your `go`
    38  command should be the `$HOME/go/bin/go` executable that you built with
    39  `make.bash` or equivalent.
    40  
    41  You can achieve this by adding the right version of `go` to your `PATH`
    42  (`export PATH=$HOME/go/bin:$PATH` on Unix systems) or by configuring your
    43  editor.
    44  
    45  To work on both `std` and `cmd` simultaneously, add a `go.work` file to
    46  `GOROOT/src`:
    47  
    48  ```
    49  cd $(go env GOROOT)/src
    50  go work init . cmd
    51  ```
    52  
    53  Note that you must work inside the `GOROOT/src` subdirectory, as the `go`
    54  command does not recognize `go.work` files in a parent of `GOROOT/src`
    55  (https://go.dev/issue/59429).
    56  
    57  ## Working with generic code
    58  
    59  Gopls has support for editing generic Go code. To enable this support, you need
    60  to **install gopls using Go 1.18 or later**. The easiest way to do this is by
    61  [installing Go 1.18+](https://go.dev/dl) and then using this Go version to
    62  install gopls:
    63  
    64  ```
    65  $ go install golang.org/x/tools/gopls@latest
    66  ```
    67  
    68  It is strongly recommended that you install the latest version of `gopls`, or
    69  the latest **unstable** version as [described above](#installing-unreleased-versions).
    70  
    71  The `gopls` built with these instructions understands generic code. See the
    72  [generics tutorial](https://go.dev/doc/tutorial/generics) for more information
    73  on how to use generics in Go!
    74  
    75  ### Known issues
    76  
    77    * [`staticcheck`](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#staticcheck-bool)
    78      on generic code is not supported yet.
    79  
    80  [Go project]: https://go.googlesource.com/go