gopls
Official Go language server
TLDR
SYNOPSIS
gopls [flags] [command] [command-flags] [args]
DESCRIPTION
gopls (pronounced "Go please") is the official language server for Go, developed by the Go team. Editors that speak the Language Server Protocol (LSP) use it for completion, diagnostics, navigation, renaming, and refactoring. You normally do not run it by hand: VS Code, Vim, Neovim, Emacs, Helix, Sublime Text, Zed, and others start gopls serve and talk to it over stdin/stdout.The same binary also exposes an experimental command-line interface for the same features. Positions are file.go:line:column with 1-based line and column in UTF-8 bytes, or file.go:#offset for a 0-based byte offset. The CLI is intended as a debugging aid; it is not efficient or officially supported as a stable API.gopls follows the Go release policy for the go toolchain it finds on $PATH (the two most recent major releases). It can still analyze source written for older Go versions according to the go directive in go.mod.
PARAMETERS
serve
Run the LSP server (default if no command is given). Speaks JSON-RPC on stdin/stdout unless --listen is set.check files
Print diagnostics for the given Go files.format [-w] files
Format Go source. --write / -w overwrites the files; default prints the formatted text.imports [-w] file
Add missing imports and remove unused ones (same edit flags as format).definition file.go:line:column
Print the location of the definition of the identifier at that position.references file.go:line:column
List references to the identifier at that position.rename [-w] file.go:line:column newname_
Rename the identifier across the module. --write / -w applies edits; default prints the new file text.version
Print the gopls version.help [command]
Help for gopls or for a subcommand (for example gopls help serve).-v, --verbose
Verbose logging.--remote addr
Forward commands to a remote gopls (tcp address, unix;path, or auto).--write, -w
With format, imports, and rename, write edits back to the source files.--diff, -d
Print unified diffs instead of full file contents.--list, -l
Print the names of files that would be edited.
CONFIGURATION
Editors pass settings through the LSP workspace/configuration request (the gopls section). A full list is at the gopls settings documentation. gopls also inherits the editor's environment, including GOROOT, GOPATH, and GOFLAGS..clangd-style project files are not used; layout is a Go module, a multi-module workspace, or GOPATH, as described in the gopls workspace documentation.
INSTALL
CAVEATS
The command-line interface is experimental and may change without notice. gopls only supports the go command as a build system; Bazel needs a go/packages driver and is not officially supported. Building gopls requires Go 1.21 or later. After upgrading, restart running gopls processes (for example killall gopls). Positions in non-ASCII files are UTF-8 byte columns, which may not match an editor's UTF-16 or code-point column.
HISTORY
gopls is maintained by the Go tools team as the successor to earlier editor integrations such as gocode and guru. It lives in golang.org/x/tools/gopls and ships on a roughly quarterly minor-release cadence aligned with the Go release cycle.
