1# Settings
2
3<!--TODO: Generate this file from the documentation in golang/org/x/tools/internal/lsp/source/options.go.-->
4
5This document describes the global settings for `gopls` inside the editor.
6The settings block will be called `"gopls"` and contains a collection of
7controls for `gopls` that the editor is not expected to understand or control.
8These settings can also be configured differently per workspace folder.
9
10In VSCode, this would be a section in your `settings.json` file that might look
11like this:
12
13```json5
14  "gopls": {
15    "ui.completion.usePlaceholders": true,
16     ...
17  },
18```
19
20## Officially supported
21
22Below is the list of settings that are officially supported for `gopls`.
23
24Any settings that are experimental or for debugging purposes are marked as
25such.
26
27To enable all experimental features, use **allExperiments: `true`**. You will
28still be able to independently override specific experimental features.
29
30<!-- BEGIN User: DO NOT MANUALLY EDIT THIS SECTION -->
31
32* [Build](#build)
33* [Formatting](#formatting)
34* [UI](#ui)
35  * [Completion](#completion)
36  * [Diagnostic](#diagnostic)
37  * [Documentation](#documentation)
38  * [Navigation](#navigation)
39
40### Build
41
42#### **buildFlags** *[]string*
43
44buildFlags is the set of flags passed on to the build system when invoked.
45It is applied to queries like `go list`, which is used when discovering files.
46The most common use is to set `-tags`.
47
48Default: `[]`.
49
50#### **env** *map[string]string*
51
52env adds environment variables to external commands run by `gopls`, most notably `go list`.
53
54Default: `{}`.
55
56#### **directoryFilters** *[]string*
57
58directoryFilters can be used to exclude unwanted directories from the
59workspace. By default, all directories are included. Filters are an
60operator, `+` to include and `-` to exclude, followed by a path prefix
61relative to the workspace folder. They are evaluated in order, and
62the last filter that applies to a path controls whether it is included.
63The path prefix can be empty, so an initial `-` excludes everything.
64
65Examples:
66
67Exclude node_modules: `-node_modules`
68
69Include only project_a: `-` (exclude everything), `+project_a`
70
71Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`
72
73Default: `[]`.
74
75#### **memoryMode** *enum*
76
77**This setting is experimental and may be deleted.**
78
79memoryMode controls the tradeoff `gopls` makes between memory usage and
80correctness.
81
82Values other than `Normal` are untested and may break in surprising ways.
83
84Must be one of:
85
86* `"DegradeClosed"`: In DegradeClosed mode, `gopls` will collect less information about
87packages without open files. As a result, features like Find
88References and Rename will miss results in such packages.
89
90* `"Normal"`
91Default: `"Normal"`.
92
93#### **expandWorkspaceToModule** *bool*
94
95**This setting is experimental and may be deleted.**
96
97expandWorkspaceToModule instructs `gopls` to adjust the scope of the
98workspace to find the best available module root. `gopls` first looks for
99a go.mod file in any parent directory of the workspace folder, expanding
100the scope to that directory if it exists. If no viable parent directory is
101found, gopls will check if there is exactly one child directory containing
102a go.mod file, narrowing the scope to that directory if it exists.
103
104Default: `true`.
105
106#### **experimentalWorkspaceModule** *bool*
107
108**This setting is experimental and may be deleted.**
109
110experimentalWorkspaceModule opts a user into the experimental support
111for multi-module workspaces.
112
113Default: `false`.
114
115#### **experimentalTemplateSupport** *bool*
116
117**This setting is experimental and may be deleted.**
118
119experimentalTemplateSupport opts into the experimental support
120for template files.
121
122Default: `false`.
123
124#### **experimentalPackageCacheKey** *bool*
125
126**This setting is experimental and may be deleted.**
127
128experimentalPackageCacheKey controls whether to use a coarser cache key
129for package type information to increase cache hits. This setting removes
130the user's environment, build flags, and working directory from the cache
131key, which should be a safe change as all relevant inputs into the type
132checking pass are already hashed into the key. This is temporarily guarded
133by an experiment because caching behavior is subtle and difficult to
134comprehensively test.
135
136Default: `true`.
137
138#### **allowModfileModifications** *bool*
139
140**This setting is experimental and may be deleted.**
141
142allowModfileModifications disables -mod=readonly, allowing imports from
143out-of-scope modules. This option will eventually be removed.
144
145Default: `false`.
146
147#### **allowImplicitNetworkAccess** *bool*
148
149**This setting is experimental and may be deleted.**
150
151allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module
152downloads rather than requiring user action. This option will eventually
153be removed.
154
155Default: `false`.
156
157#### **experimentalUseInvalidMetadata** *bool*
158
159**This setting is experimental and may be deleted.**
160
161experimentalUseInvalidMetadata enables gopls to fall back on outdated
162package metadata to provide editor features if the go command fails to
163load packages for some reason (like an invalid go.mod file). This will
164eventually be the default behavior, and this setting will be removed.
165
166Default: `false`.
167
168### Formatting
169
170#### **local** *string*
171
172local is the equivalent of the `goimports -local` flag, which puts
173imports beginning with this string after third-party packages. It should
174be the prefix of the import path whose imports should be grouped
175separately.
176
177Default: `""`.
178
179#### **gofumpt** *bool*
180
181gofumpt indicates if we should run gofumpt formatting.
182
183Default: `false`.
184
185### UI
186
187#### **codelenses** *map[string]bool*
188
189codelenses overrides the enabled/disabled state of code lenses. See the
190"Code Lenses" section of the
191[Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md)
192for the list of supported lenses.
193
194Example Usage:
195
196```json5
197"gopls": {
198...
199  "codelens": {
200    "generate": false,  // Don't show the `go generate` lens.
201    "gc_details": true  // Show a code lens toggling the display of gc's choices.
202  }
203...
204}
205```
206
207Default: `{"gc_details":false,"generate":true,"regenerate_cgo":true,"tidy":true,"upgrade_dependency":true,"vendor":true}`.
208
209#### **semanticTokens** *bool*
210
211**This setting is experimental and may be deleted.**
212
213semanticTokens controls whether the LSP server will send
214semantic tokens to the client.
215
216Default: `false`.
217
218#### Completion
219
220##### **usePlaceholders** *bool*
221
222placeholders enables placeholders for function parameters or struct
223fields in completion responses.
224
225Default: `false`.
226
227##### **completionBudget** *time.Duration*
228
229**This setting is for debugging purposes only.**
230
231completionBudget is the soft latency goal for completion requests. Most
232requests finish in a couple milliseconds, but in some cases deep
233completions can take much longer. As we use up our budget we
234dynamically reduce the search scope to ensure we return timely
235results. Zero means unlimited.
236
237Default: `"100ms"`.
238
239##### **matcher** *enum*
240
241**This is an advanced setting and should not be configured by most `gopls` users.**
242
243matcher sets the algorithm that is used when calculating completion
244candidates.
245
246Must be one of:
247
248* `"CaseInsensitive"`
249* `"CaseSensitive"`
250* `"Fuzzy"`
251Default: `"Fuzzy"`.
252
253##### **experimentalPostfixCompletions** *bool*
254
255**This setting is experimental and may be deleted.**
256
257experimentalPostfixCompletions enables artifical method snippets
258such as "someSlice.sort!".
259
260Default: `true`.
261
262#### Diagnostic
263
264##### **analyses** *map[string]bool*
265
266analyses specify analyses that the user would like to enable or disable.
267A map of the names of analysis passes that should be enabled/disabled.
268A full list of analyzers that gopls uses can be found
269[here](https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md).
270
271Example Usage:
272
273```json5
274...
275"analyses": {
276  "unreachable": false, // Disable the unreachable analyzer.
277  "unusedparams": true  // Enable the unusedparams analyzer.
278}
279...
280```
281
282Default: `{}`.
283
284##### **staticcheck** *bool*
285
286**This setting is experimental and may be deleted.**
287
288staticcheck enables additional analyses from staticcheck.io.
289
290Default: `false`.
291
292##### **annotations** *map[string]bool*
293
294**This setting is experimental and may be deleted.**
295
296annotations specifies the various kinds of optimization diagnostics
297that should be reported by the gc_details command.
298
299Can contain any of:
300
301* `"bounds"` controls bounds checking diagnostics.
302
303* `"escape"` controls diagnostics about escape choices.
304
305* `"inline"` controls diagnostics about inlining choices.
306
307* `"nil"` controls nil checks.
308
309Default: `{"bounds":true,"escape":true,"inline":true,"nil":true}`.
310
311##### **diagnosticsDelay** *time.Duration*
312
313**This is an advanced setting and should not be configured by most `gopls` users.**
314
315diagnosticsDelay controls the amount of time that gopls waits
316after the most recent file modification before computing deep diagnostics.
317Simple diagnostics (parsing and type-checking) are always run immediately
318on recently modified packages.
319
320This option must be set to a valid duration string, for example `"250ms"`.
321
322Default: `"250ms"`.
323
324##### **experimentalWatchedFileDelay** *time.Duration*
325
326**This setting is experimental and may be deleted.**
327
328experimentalWatchedFileDelay controls the amount of time that gopls waits
329for additional workspace/didChangeWatchedFiles notifications to arrive,
330before processing all such notifications in a single batch. This is
331intended for use by LSP clients that don't support their own batching of
332file system notifications.
333
334This option must be set to a valid duration string, for example `"100ms"`.
335
336Default: `"0s"`.
337
338#### Documentation
339
340##### **hoverKind** *enum*
341
342hoverKind controls the information that appears in the hover text.
343SingleLine and Structured are intended for use only by authors of editor plugins.
344
345Must be one of:
346
347* `"FullDocumentation"`
348* `"NoDocumentation"`
349* `"SingleLine"`
350* `"Structured"` is an experimental setting that returns a structured hover format.
351This format separates the signature from the documentation, so that the client
352can do more manipulation of these fields.\
353This should only be used by clients that support this behavior.
354
355* `"SynopsisDocumentation"`
356Default: `"FullDocumentation"`.
357
358##### **linkTarget** *string*
359
360linkTarget controls where documentation links go.
361It might be one of:
362
363* `"godoc.org"`
364* `"pkg.go.dev"`
365
366If company chooses to use its own `godoc.org`, its address can be used as well.
367
368Default: `"pkg.go.dev"`.
369
370##### **linksInHover** *bool*
371
372linksInHover toggles the presence of links to documentation in hover.
373
374Default: `true`.
375
376#### Navigation
377
378##### **importShortcut** *enum*
379
380importShortcut specifies whether import statements should link to
381documentation or go to definitions.
382
383Must be one of:
384
385* `"Both"`
386* `"Definition"`
387* `"Link"`
388Default: `"Both"`.
389
390##### **symbolMatcher** *enum*
391
392**This is an advanced setting and should not be configured by most `gopls` users.**
393
394symbolMatcher sets the algorithm that is used when finding workspace symbols.
395
396Must be one of:
397
398* `"CaseInsensitive"`
399* `"CaseSensitive"`
400* `"Fuzzy"`
401Default: `"Fuzzy"`.
402
403##### **symbolStyle** *enum*
404
405**This is an advanced setting and should not be configured by most `gopls` users.**
406
407symbolStyle controls how symbols are qualified in symbol responses.
408
409Example Usage:
410
411```json5
412"gopls": {
413...
414  "symbolStyle": "dynamic",
415...
416}
417```
418
419Must be one of:
420
421* `"Dynamic"` uses whichever qualifier results in the highest scoring
422match for the given symbol query. Here a "qualifier" is any "/" or "."
423delimited suffix of the fully qualified symbol. i.e. "to/pkg.Foo.Field" or
424just "Foo.Field".
425
426* `"Full"` is fully qualified symbols, i.e.
427"path/to/pkg.Foo.Field".
428
429* `"Package"` is package qualified symbols i.e.
430"pkg.Foo.Field".
431
432Default: `"Dynamic"`.
433
434#### **verboseOutput** *bool*
435
436**This setting is for debugging purposes only.**
437
438verboseOutput enables additional debug logging.
439
440Default: `false`.
441
442<!-- END User: DO NOT MANUALLY EDIT THIS SECTION -->
443
444## Code Lenses
445
446These are the code lenses that `gopls` currently supports. They can be enabled
447and disabled using the `codelenses` setting, documented above. Their names and
448features are subject to change.
449
450<!-- BEGIN Lenses: DO NOT MANUALLY EDIT THIS SECTION -->
451### **Toggle gc_details**
452
453Identifier: `gc_details`
454
455Toggle the calculation of gc annotations.
456### **Run go generate**
457
458Identifier: `generate`
459
460Runs `go generate` for a given directory.
461### **Regenerate cgo**
462
463Identifier: `regenerate_cgo`
464
465Regenerates cgo definitions.
466### **Run test(s) (legacy)**
467
468Identifier: `test`
469
470Runs `go test` for a specific set of test or benchmark functions.
471### **Run go mod tidy**
472
473Identifier: `tidy`
474
475Runs `go mod tidy` for a module.
476### **Upgrade a dependency**
477
478Identifier: `upgrade_dependency`
479
480Upgrades a dependency in the go.mod file for a module.
481### **Run go mod vendor**
482
483Identifier: `vendor`
484
485Runs `go mod vendor` for a module.
486<!-- END Lenses: DO NOT MANUALLY EDIT THIS SECTION -->
487