| 1 | --- |
| 2 | title: "Gopls: The language server for Go" |
| 3 | --- |
| 4 | <!-- |
| 5 | This is the main landing page for gopls users. |
| 6 | |
| 7 | To preview locally edited markdown files, use: |
| 8 | $ GOLANGORG_LOCAL_X_TOOLS=$(pwd) go run golang.org/x/website/cmd/golangorg@master & |
| 9 | $ open http://localhost:6060/go.dev/gopls |
| 10 | --> |
| 11 | |
| 12 | `gopls` (pronounced "Go please") is the official [language |
| 13 | server](https://langserver.org) for Go, developed by the Go team. It |
| 14 | provides a wide variety of [IDE features](features/) to any |
| 15 | [LSP](https://microsoft.github.io/language-server-protocol/)-compatible |
| 16 | editor. |
| 17 | |
| 18 | <!--TODO(rfindley): Add gifs here.--> |
| 19 | |
| 20 | You should not need to interact with `gopls` directly--it will be automatically |
| 21 | integrated into your editor. The specific features and settings vary slightly |
| 22 | by editor, so we recommend that you proceed to the |
| 23 | [documentation for your editor](#editors) below. |
| 24 | Also, the gopls documentation for each feature describes whether it is |
| 25 | supported in each client editor. |
| 26 | |
| 27 | This documentation (https://go.dev/gopls) describes the most recent release of gopls. |
| 28 | To preview documentation for the release under development, visit https://tip.golang.org/gopls. |
| 29 | |
| 30 | ## Features |
| 31 | |
| 32 | Gopls supports a wide range of standard LSP features for navigation, |
| 33 | completion, diagnostics, analysis, and refactoring, and a number of |
| 34 | additional features not found in other language servers. |
| 35 | |
| 36 | See the [Index of features](features/) for complete |
| 37 | documentation on what Gopls can do for you. |
| 38 | |
| 39 | ## Editors |
| 40 | |
| 41 | To get started with `gopls`, install an LSP plugin in your editor of choice. |
| 42 | |
| 43 | <!-- TODO: be more consistent about editor (e.g. Emacs) vs. client (e.g. eglot). --> |
| 44 | |
| 45 | * [Acme](https://github.com/9fans/acme-lsp/blob/master/README.md) |
| 46 | * [Atom](https://github.com/MordFustang21/ide-gopls/blob/master/README.md) |
| 47 | * [Emacs](editor/emacs.md) |
| 48 | * [Helix](editor/helix.md) |
| 49 | * [Lapce](https://github.com/lapce-community/lapce-go/blob/master/README.md) |
| 50 | * [Sublime Text](editor/sublime.md) |
| 51 | * [VS Code](https://github.com/golang/vscode-go/blob/master/README.md) |
| 52 | * [Vim or Neovim](editor/vim.md) |
| 53 | * [Zed](editor/zed.md) |
| 54 | |
| 55 | If you use `gopls` with an editor that is not on this list, please send us a CL |
| 56 | [updating this documentation](contributing.md). |
| 57 | |
| 58 | ## Installation |
| 59 | |
| 60 | To install the latest stable release of `gopls`, run the following command: |
| 61 | |
| 62 | ```sh |
| 63 | go install golang.org/x/tools/gopls@latest |
| 64 | ``` |
| 65 | |
| 66 | Some editors, such as VS Code, will handle this step for you, and |
| 67 | ensure that Gopls is updated when a new stable version is released. |
| 68 | |
| 69 | After updating, you may need to restart running Gopls processes to |
| 70 | observe the effect. Each client has its own way to restart the server. |
| 71 | (On a UNIX machine, you can use the command `killall gopls`.) |
| 72 | |
| 73 | Learn more in the |
| 74 | [advanced installation instructions](advanced.md#installing-unreleased-versions). |
| 75 | |
| 76 | ## Releases |
| 77 | |
| 78 | Gopls [releases](release/) follow [semantic versioning](http://semver.org), with |
| 79 | major changes and new features introduced only in new minor versions |
| 80 | (i.e. versions of the form `v*.N.0` for some N). Subsequent patch |
| 81 | releases contain only cherry-picked fixes or superficial updates. |
| 82 | |
| 83 | In order to align with the |
| 84 | [Go release timeline](https://github.com/golang/go/wiki/Go-Release-Cycle#timeline), |
| 85 | we aim to release a new minor version of Gopls approximately every three |
| 86 | months, with patch releases approximately every month, according to the |
| 87 | following table: |
| 88 | |
| 89 | | Month | Version(s) | |
| 90 | | ---- | ------- | |
| 91 | | Jan | `v*.<N+0>.0` | |
| 92 | | Jan-Mar | `v*.<N+0>.*` | |
| 93 | | Apr | `v*.<N+1>.0` | |
| 94 | | Apr-Jun | `v*.<N+1>.*` | |
| 95 | | Jul | `v*.<N+2>.0` | |
| 96 | | Jul-Sep | `v*.<N+2>.*` | |
| 97 | | Oct | `v*.<N+3>.0` | |
| 98 | | Oct-Dec | `v*.<N+3>.*` | |
| 99 | |
| 100 | For more background on this policy, see https://go.dev/issue/55267. |
| 101 | |
| 102 | ## Setting up your workspace |
| 103 | |
| 104 | `gopls` supports both Go module, multi-module and GOPATH modes. See the |
| 105 | [workspace documentation](workspace.md) for information on supported |
| 106 | workspace layouts. |
| 107 | |
| 108 | ## Configuration |
| 109 | |
| 110 | You can configure `gopls` to change your editor experience or view additional |
| 111 | debugging information. Configuration options will be made available by your |
| 112 | editor, so see your [editor's instructions](#editors) for specific details. A |
| 113 | full list of `gopls` settings can be found in the [settings documentation](settings.md). |
| 114 | |
| 115 | ### Environment variables |
| 116 | |
| 117 | `gopls` inherits your editor's environment, so be aware of any environment |
| 118 | variables you configure. Some editors, such as VS Code, allow users to |
| 119 | selectively override the values of some environment variables. |
| 120 | |
| 121 | ## Support policy |
| 122 | |
| 123 | Gopls is maintained by engineers on the |
| 124 | [Go tools team](https://github.com/orgs/golang/teams/tools-team/members), |
| 125 | who actively monitor the |
| 126 | [Go](https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3Agopls) |
| 127 | and |
| 128 | [VS Code Go](https://github.com/golang/vscode-go/issues) issue trackers. |
| 129 | |
| 130 | ### Supported Go versions |
| 131 | |
| 132 | When using gopls, there are three distinct versions of Go to be aware of: |
| 133 | the `go` toolchain used to build gopls, |
| 134 | the `go` toolchain on the `PATH` when gopls is running, |
| 135 | and the version of Go in which your source code is written. |
| 136 | |
| 137 | To build gopls, you must use a toolchain supporting Go 1.21 or later. |
| 138 | Go 1.21 was the first version of Go to support [forward |
| 139 | compatibility](https://go.dev/blog/toolchain), which ensures that any |
| 140 | necessary toolchain upgrades are handled automatically, just like any |
| 141 | other dependency. |
| 142 | |
| 143 | While running, gopls executes the `go` command found using `$PATH` to |
| 144 | obtain information about your workspace. Gopls follows the [Go Release |
| 145 | Policy](https://go.dev/doc/devel/release#policy), meaning that we |
| 146 | support only the two most recent major Go releases. |
| 147 | Run `go version` to check this version. |
| 148 | (Supporting older versions caused significant maintenance |
| 149 | [friction](https://go.dev/issue/50825). If you are unable to use a |
| 150 | supported toolchain, you can install an older version of gopls.) |
| 151 | |
| 152 | Gopls can analyze code written using any version of Go, and will |
| 153 | tailor its diagnostics and other behavior to the appropriate version |
| 154 | of Go for each source file. |
| 155 | The file's Go version is determined by the `go` directive in the |
| 156 | enclosing go.mod file and by any build tags such as `//go:build |
| 157 | go1.25` within the file itself. |
| 158 | |
| 159 | ### Supported build systems |
| 160 | |
| 161 | `gopls` currently only supports the `go` command, so if you are using |
| 162 | a different build system, `gopls` will not work well. Bazel is not officially |
| 163 | supported, but may be made to work with an appropriately configured |
| 164 | [go/packages driver](https://pkg.go.dev/golang.org/x/tools/go/packages#hdr-The_driver_protocol). |
| 165 | See [bazelbuild/rules_go#512](https://github.com/bazelbuild/rules_go/issues/512) |
| 166 | for more information. |
| 167 | You can follow [these instructions](https://github.com/bazelbuild/rules_go/wiki/Editor-setup) |
| 168 | to configure your `gopls` to work with Bazel. |
| 169 | |
| 170 | ### Troubleshooting |
| 171 | |
| 172 | If you are having issues with `gopls`, please follow the steps described in the |
| 173 | [troubleshooting guide](troubleshooting.md). |
| 174 | |
| 175 | ## Additional information |
| 176 | |
| 177 | * [Command-line interface](command-line.md) |
| 178 | * [Advanced topics](advanced.md) |
| 179 | * [Open issues](https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3Agopls) |
| 180 | * [Contributing to `gopls`](contributing.md) |