3 <!--TODO: Generate this file from the documentation in golang/org/x/tools/internal/lsp/source/options.go.-->
5 This document describes the global settings for `gopls` inside the editor.
6 The settings block will be called `"gopls"` and contains a collection of
7 controls for `gopls` that the editor is not expected to understand or control.
8 These settings can also be configured differently per workspace folder.
10 In VSCode, this would be a section in your `settings.json` file that might look
15 "ui.completion.usePlaceholders": true,
20 ## Officially supported
22 Below is the list of settings that are officially supported for `gopls`.
24 Any settings that are experimental or for debugging purposes are marked as
27 To enable all experimental features, use **allExperiments: `true`**. You will
28 still be able to independently override specific experimental features.
30 <!-- BEGIN User: DO NOT MANUALLY EDIT THIS SECTION -->
33 * [Formatting](#formatting)
35 * [Completion](#completion)
36 * [Diagnostic](#diagnostic)
37 * [Documentation](#documentation)
38 * [Navigation](#navigation)
42 #### **buildFlags** *[]string*
44 buildFlags is the set of flags passed on to the build system when invoked.
45 It is applied to queries like `go list`, which is used when discovering files.
46 The most common use is to set `-tags`.
50 #### **env** *map[string]string*
52 env adds environment variables to external commands run by `gopls`, most notably `go list`.
56 #### **directoryFilters** *[]string*
58 directoryFilters can be used to exclude unwanted directories from the
59 workspace. By default, all directories are included. Filters are an
60 operator, `+` to include and `-` to exclude, followed by a path prefix
61 relative to the workspace folder. They are evaluated in order, and
62 the last filter that applies to a path controls whether it is included.
63 The path prefix can be empty, so an initial `-` excludes everything.
66 Exclude node_modules: `-node_modules`
67 Include only project_a: `-` (exclude everything), `+project_a`
68 Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`
72 #### **expandWorkspaceToModule** *bool*
74 **This setting is experimental and may be deleted.**
76 expandWorkspaceToModule instructs `gopls` to adjust the scope of the
77 workspace to find the best available module root. `gopls` first looks for
78 a go.mod file in any parent directory of the workspace folder, expanding
79 the scope to that directory if it exists. If no viable parent directory is
80 found, gopls will check if there is exactly one child directory containing
81 a go.mod file, narrowing the scope to that directory if it exists.
85 #### **experimentalWorkspaceModule** *bool*
87 **This setting is experimental and may be deleted.**
89 experimentalWorkspaceModule opts a user into the experimental support
90 for multi-module workspaces.
94 #### **experimentalPackageCacheKey** *bool*
96 **This setting is experimental and may be deleted.**
98 experimentalPackageCacheKey controls whether to use a coarser cache key
99 for package type information to increase cache hits. This setting removes
100 the user's environment, build flags, and working directory from the cache
101 key, which should be a safe change as all relevant inputs into the type
102 checking pass are already hashed into the key. This is temporarily guarded
103 by an experiment because caching behavior is subtle and difficult to
104 comprehensively test.
108 #### **allowModfileModifications** *bool*
110 **This setting is experimental and may be deleted.**
112 allowModfileModifications disables -mod=readonly, allowing imports from
113 out-of-scope modules. This option will eventually be removed.
117 #### **allowImplicitNetworkAccess** *bool*
119 **This setting is experimental and may be deleted.**
121 allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module
122 downloads rather than requiring user action. This option will eventually
129 #### **local** *string*
131 local is the equivalent of the `goimports -local` flag, which puts
132 imports beginning with this string after third-party packages. It should
133 be the prefix of the import path whose imports should be grouped
138 #### **gofumpt** *bool*
140 gofumpt indicates if we should run gofumpt formatting.
146 #### **codelenses** *map[string]bool*
148 codelenses overrides the enabled/disabled state of code lenses. See the
149 "Code Lenses" section of the
150 [Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md)
151 for the list of supported lenses.
159 "generate": false, // Don't show the `go generate` lens.
160 "gc_details": true // Show a code lens toggling the display of gc's choices.
166 Default: `{"gc_details":false,"generate":true,"regenerate_cgo":true,"tidy":true,"upgrade_dependency":true,"vendor":true}`.
168 #### **semanticTokens** *bool*
170 **This setting is experimental and may be deleted.**
172 semanticTokens controls whether the LSP server will send
173 semantic tokens to the client.
179 ##### **usePlaceholders** *bool*
181 placeholders enables placeholders for function parameters or struct
182 fields in completion responses.
186 ##### **completionBudget** *time.Duration*
188 **This setting is for debugging purposes only.**
190 completionBudget is the soft latency goal for completion requests. Most
191 requests finish in a couple milliseconds, but in some cases deep
192 completions can take much longer. As we use up our budget we
193 dynamically reduce the search scope to ensure we return timely
194 results. Zero means unlimited.
198 ##### **matcher** *enum*
200 **This is an advanced setting and should not be configured by most `gopls` users.**
202 matcher sets the algorithm that is used when calculating completion
207 * `"CaseInsensitive"`
214 ##### **analyses** *map[string]bool*
216 analyses specify analyses that the user would like to enable or disable.
217 A map of the names of analysis passes that should be enabled/disabled.
218 A full list of analyzers that gopls uses can be found
219 [here](https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md).
226 "unreachable": false, // Disable the unreachable analyzer.
227 "unusedparams": true // Enable the unusedparams analyzer.
234 ##### **staticcheck** *bool*
236 **This setting is experimental and may be deleted.**
238 staticcheck enables additional analyses from staticcheck.io.
242 ##### **annotations** *map[string]bool*
244 **This setting is experimental and may be deleted.**
246 annotations specifies the various kinds of optimization diagnostics
247 that should be reported by the gc_details command.
251 * `"bounds"` controls bounds checking diagnostics.
253 * `"escape"` controls diagnostics about escape choices.
255 * `"inline"` controls diagnostics about inlining choices.
257 * `"nil"` controls nil checks.
259 Default: `{"bounds":true,"escape":true,"inline":true,"nil":true}`.
261 ##### **experimentalDiagnosticsDelay** *time.Duration*
263 **This setting is experimental and may be deleted.**
265 experimentalDiagnosticsDelay controls the amount of time that gopls waits
266 after the most recent file modification before computing deep diagnostics.
267 Simple diagnostics (parsing and type-checking) are always run immediately
268 on recently modified packages.
270 This option must be set to a valid duration string, for example `"250ms"`.
276 ##### **hoverKind** *enum*
278 hoverKind controls the information that appears in the hover text.
279 SingleLine and Structured are intended for use only by authors of editor plugins.
283 * `"FullDocumentation"`
284 * `"NoDocumentation"`
286 * `"Structured"` is an experimental setting that returns a structured hover format.
287 This format separates the signature from the documentation, so that the client
288 can do more manipulation of these fields.\
289 This should only be used by clients that support this behavior.
291 * `"SynopsisDocumentation"`
292 Default: `"FullDocumentation"`.
294 ##### **linkTarget** *string*
296 linkTarget controls where documentation links go.
302 If company chooses to use its own `godoc.org`, its address can be used as well.
304 Default: `"pkg.go.dev"`.
306 ##### **linksInHover** *bool*
308 linksInHover toggles the presence of links to documentation in hover.
314 ##### **importShortcut** *enum*
316 importShortcut specifies whether import statements should link to
317 documentation or go to definitions.
326 ##### **symbolMatcher** *enum*
328 **This is an advanced setting and should not be configured by most `gopls` users.**
330 symbolMatcher sets the algorithm that is used when finding workspace symbols.
334 * `"CaseInsensitive"`
339 ##### **symbolStyle** *enum*
341 **This is an advanced setting and should not be configured by most `gopls` users.**
343 symbolStyle controls how symbols are qualified in symbol responses.
350 "symbolStyle": "dynamic",
357 * `"Dynamic"` uses whichever qualifier results in the highest scoring
358 match for the given symbol query. Here a "qualifier" is any "/" or "."
359 delimited suffix of the fully qualified symbol. i.e. "to/pkg.Foo.Field" or
362 * `"Full"` is fully qualified symbols, i.e.
363 "path/to/pkg.Foo.Field".
365 * `"Package"` is package qualified symbols i.e.
368 Default: `"Dynamic"`.
370 #### **verboseOutput** *bool*
372 **This setting is for debugging purposes only.**
374 verboseOutput enables additional debug logging.
378 <!-- END User: DO NOT MANUALLY EDIT THIS SECTION -->
382 These are the code lenses that `gopls` currently supports. They can be enabled
383 and disabled using the `codelenses` setting, documented above. Their names and
384 features are subject to change.
386 <!-- BEGIN Lenses: DO NOT MANUALLY EDIT THIS SECTION -->
387 ### **Toggle gc_details**
389 Identifier: `gc_details`
391 Toggle the calculation of gc annotations.
392 ### **Run go generate**
394 Identifier: `generate`
396 Runs `go generate` for a given directory.
397 ### **Regenerate cgo**
399 Identifier: `regenerate_cgo`
401 Regenerates cgo definitions.
402 ### **Run test(s) (legacy)**
406 Runs `go test` for a specific set of test or benchmark functions.
407 ### **Run go mod tidy**
411 Runs `go mod tidy` for a module.
412 ### **Upgrade dependency**
414 Identifier: `upgrade_dependency`
416 Upgrades a dependency in the go.mod file for a module.
417 ### **Run go mod vendor**
421 Runs `go mod vendor` for a module.
422 <!-- END Lenses: DO NOT MANUALLY EDIT THIS SECTION -->