This document describes the global settings for gopls
inside the editor. The settings block will be called "gopls"
and contains a collection of controls for gopls
that the editor is not expected to understand or control. These settings can also be configured differently per workspace folder.
In VSCode, this would be a section in your settings.json
file that might look like this:
"gopls": { "usePlaceholders": true, "completeUnimported": true },
Below is the list of settings that are officially supported for gopls
.
To enable all experimental features, use allExperiments: true
. You will still be able to independently override specific experimental features.
buildFlags is the set of flags passed on to the build system when invoked. It is applied to queries like go list
, which is used when discovering files. The most common use is to set -tags
.
Default: []
.
env adds environment variables to external commands run by gopls
, most notably go list
.
Default: {}
.
hoverKind controls the information that appears in the hover text. SingleLine and Structured are intended for use only by authors of editor plugins. Must be one of:
"FullDocumentation"
"NoDocumentation"
"SingleLine"
"Structured"
is an experimental setting that returns a structured hover format. This format separates the signature from the documentation, so that the client can do more manipulation of these fields.
This should only be used by clients that support this behavior.
"SynopsisDocumentation"
Default: "FullDocumentation"
.
placeholders enables placeholders for function parameters or struct fields in completion responses.
Default: false
.
linkTarget controls where documentation links go. It might be one of:
"godoc.org"
"pkg.go.dev"
If company chooses to use its own godoc.org
, its address can be used as well.
Default: "pkg.go.dev"
.
local is the equivalent of the goimports -local
flag, which puts imports beginning with this string after 3rd-party packages. It should be the prefix of the import path whose imports should be grouped separately.
Default: ""
.
gofumpt indicates if we should run gofumpt formatting.
Default: false
.
The below settings are considered experimental. They may be deprecated or changed in the future. They are typically used to test experimental opt-in features or to disable features.
analyses specify analyses that the user would like to enable or disable. A map of the names of analysis passes that should be enabled/disabled. A full list of analyzers that gopls uses can be found here
Example Usage:
... "analyses": { "unreachable": false, // Disable the unreachable analyzer. "unusedparams": true // Enable the unusedparams analyzer. } ...
Default: {}
.
codelens overrides the enabled/disabled state of code lenses. See the “Code Lenses” section of settings.md for the list of supported lenses.
Example Usage:
"gopls": { ... "codelens": { "generate": false, // Don't show the `go generate` lens. "gc_details": true // Show a code lens toggling the display of gc's choices. } ... }
Default: {"gc_details":false,"generate":true,"regenerate_cgo":true,"tidy":true,"upgrade_dependency":true,"vendor":true}
.
completionDocumentation enables documentation with completion results.
Default: true
.
completeUnimported enables completion for packages that you do not currently import.
Default: true
.
deepCompletion enables the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones.
Consider this example:
package main
import "fmt"
type wrapString struct {
str string
}
func main() {
x := wrapString{"hello world"}
fmt.Printf(<>)
}
At the location of the <>
in this program, deep completion would suggest the result x.str
.
Default: true
.
matcher sets the algorithm that is used when calculating completion candidates. Must be one of:
"CaseInsensitive"
"CaseSensitive"
"Fuzzy"
Default: "Fuzzy"
.
annotations suppress various kinds of optimization diagnostics that would be reported by the gc_details command.
Default: {}
.
staticcheck enables additional analyses from staticcheck.io.
Default: false
.
symbolMatcher sets the algorithm that is used when finding workspace symbols. Must be one of:
"CaseInsensitive"
"CaseSensitive"
"Fuzzy"
Default: "Fuzzy"
.
symbolStyle controls how symbols are qualified in symbol responses.
Example Usage:
"gopls": { ... "symbolStyle": "dynamic", ... }
Must be one of:
"Dynamic"
uses whichever qualifier results in the highest scoring match for the given symbol query. Here a “qualifier” is any “/” or “.” delimited suffix of the fully qualified symbol. i.e. “to/pkg.Foo.Field” or just “Foo.Field”.
"Full"
is fully qualified symbols, i.e. “path/to/pkg.Foo.Field”.
"Package"
is package qualified symbols i.e. “pkg.Foo.Field”.
Default: "Package"
.
linksInHover toggles the presence of links to documentation in hover.
Default: true
.
tempModfile controls the use of the -modfile flag in Go 1.14.
Default: true
.
importShortcut specifies whether import statements should link to documentation or go to definitions. Must be one of:
"Both"
"Definition"
"Link"
Default: "Both"
.
verboseWorkDoneProgress controls whether the LSP server should send progress reports for all work done outside the scope of an RPC.
Default: false
.
semanticTokens controls whether the LSP server will send semantic tokens to the client.
Default: false
.
expandWorkspaceToModule instructs gopls
to adjust the scope of the workspace to find the best available module root. gopls
first looks for a go.mod file in any parent directory of the workspace folder, expanding the scope to that directory if it exists. If no viable parent directory is found, gopls will check if there is exactly one child directory containing a go.mod file, narrowing the scope to that directory if it exists.
Default: true
.
experimentalWorkspaceModule opts a user into the experimental support for multi-module workspaces.
Default: false
.
experimentalDiagnosticsDelay controls the amount of time that gopls waits after the most recent file modification before computing deep diagnostics. Simple diagnostics (parsing and type-checking) are always run immediately on recently modified packages.
This option must be set to a valid duration string, for example "250ms"
.
Default: "0s"
.
experimentalPackageCacheKey controls whether to use a coarser cache key for package type information to increase cache hits. This setting removes the user's environment, build flags, and working directory from the cache key, which should be a safe change as all relevant inputs into the type checking pass are already hashed into the key. This is temporarily guarded by an experiment because caching behavior is subtle and difficult to comprehensively test.
Default: true
.
The below settings are for use in debugging gopls
. Like the experimental options, they may be deprecated or changed in the future.
verboseOutput enables additional debug logging.
Default: false
.
completionBudget is the soft latency goal for completion requests. Most requests finish in a couple milliseconds, but in some cases deep completions can take much longer. As we use up our budget we dynamically reduce the search scope to ensure we return timely results. Zero means unlimited.
Default: "100ms"
.
These are the code lenses that gopls
currently supports. They can be enabled and disabled using the codeLenses
setting, documented above. The names and features are subject to change.
Identifier: generate
generate runs go generate
for a given directory.
Identifier: regenerate_cgo
regenerate_cgo regenerates cgo definitions.
Identifier: test
test runs go test
for a specific test function.
Identifier: tidy
tidy runs go mod tidy
for a module.
Identifier: upgrade_dependency
upgrade_dependency upgrades a dependency.
Identifier: vendor
vendor runs go mod vendor
for a module.
Identifier: gc_details
gc_details controls calculation of gc annotations.