Debian Codegraph @

gopls/doc/settings.md

raw symbols SCIP
1 ---
2 title: "Gopls: Settings"
3 ---
4
5 This document describes gopls' configuration settings.
6
7 Gopls settings are defined by a JSON object whose valid fields are
8 described below. These fields are gopls-specific, and generic LSP
9 clients have no knowledge of them.
10
11 Different clients present configuration settings in their user
12 interfaces in a wide variety of ways.
13 For example, some expect the user to edit the raw JSON object while
14 others use a data structure in the editor's configuration language;
15 still others (such as VS Code) have a graphical configuration system.
16 Be sure to consult the documentation for how to express configuration
17 settings in your client.
18 Some clients also permit settings to be configured differently for
19 each workspace folder.
20
21 Any settings that are experimental or for debugging purposes are
22 marked as such.
23
24 <!--
25 All settings are uniquely identified by name such as `semanticTokens`
26 or `templateExtensions`.
27 However, for convenience of VS Code, each setting also has an
28 undocumented alias whose form is a dotted path such as
29 `ui.semanticTokens` or `build.templateExtensions`.
30 However, only the final segment is actually significant, so
31 `build.templateExtensions` is equivalent to `templateExtensions`.
32 All clients but VS Code should use the short form.
33 -->
34
35 <!-- This portion is generated by doc/generate from the ../internal/settings package. -->
36 <!-- BEGIN User: DO NOT MANUALLY EDIT THIS SECTION -->
37
38 * [Build](#build)
39 * [Formatting](#formatting)
40 * [UI](#ui)
41 * [Completion](#completion)
42 * [Diagnostic](#diagnostic)
43 * [Documentation](#documentation)
44 * [Inlayhint](#inlayhint)
45 * [Navigation](#navigation)
46
47 <a id='build'></a>
48 ## Build
49
50 <a id='buildFlags'></a>
51 ### `buildFlags []string`
52
53 buildFlags is the set of flags passed on to the build system when invoked.
54 It is applied to queries like `go list`, which is used when discovering files.
55 The most common use is to set `-tags`.
56
57 Default: `[]`.
58
59 <a id='env'></a>
60 ### `env map[string]string`
61
62 env adds environment variables to external commands run by `gopls`, most notably `go list`.
63
64 Default: `{}`.
65
66 <a id='directoryFilters'></a>
67 ### `directoryFilters []string`
68
69 directoryFilters can be used to exclude unwanted directories from the
70 workspace. By default, all directories are included. Filters are an
71 operator, `+` to include and `-` to exclude, followed by a path prefix
72 relative to the workspace folder. They are evaluated in order, and
73 the last filter that applies to a path controls whether it is included.
74 The path prefix can be empty, so an initial `-` excludes everything.
75
76 DirectoryFilters also supports the `**` operator to match 0 or more directories.
77
78 Examples:
79
80 Exclude node_modules at current depth: `-node_modules`
81
82 Exclude node_modules at any depth: `-**/node_modules`
83
84 Include only project_a: `-` (exclude everything), `+project_a`
85
86 Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`
87
88 Default: `["-**/node_modules"]`.
89
90 <a id='templateExtensions'></a>
91 ### `templateExtensions []string`
92
93 templateExtensions gives the extensions of file names that are treated
94 as template files. (The extension
95 is the part of the file name after the final dot.)
96
97 Default: `[]`.
98
99 <a id='memoryMode'></a>
100 ### `memoryMode string`
101
102 **This setting is experimental and may be deleted.**
103
104 obsolete, no effect
105
106 Default: `""`.
107
108 <a id='expandWorkspaceToModule'></a>
109 ### `expandWorkspaceToModule bool`
110
111 **This setting is experimental and may be deleted.**
112
113 expandWorkspaceToModule determines which packages are considered
114 "workspace packages" when the workspace is using modules.
115
116 Workspace packages affect the scope of workspace-wide operations. Notably,
117 gopls diagnoses all packages considered to be part of the workspace after
118 every keystroke, so by setting "ExpandWorkspaceToModule" to false, and
119 opening a nested workspace directory, you can reduce the amount of work
120 gopls has to do to keep your workspace up to date.
121
122 Default: `true`.
123
124 <a id='standaloneTags'></a>
125 ### `standaloneTags []string`
126
127 standaloneTags specifies a set of build constraints that identify
128 individual Go source files that make up the entire main package of an
129 executable.
130
131 A common example of standalone main files is the convention of using the
132 directive `//go:build ignore` to denote files that are not intended to be
133 included in any package, for example because they are invoked directly by
134 the developer using `go run`.
135
136 Gopls considers a file to be a standalone main file if and only if it has
137 package name "main" and has a build directive of the exact form
138 "//go:build tag" or "// +build tag", where tag is among the list of tags
139 configured by this setting. Notably, if the build constraint is more
140 complicated than a simple tag (such as the composite constraint
141 `//go:build tag && go1.18`), the file is not considered to be a standalone
142 main file.
143
144 This setting is only supported when gopls is built with Go 1.16 or later.
145
146 Default: `["ignore"]`.
147
148 <a id='workspaceFiles'></a>
149 ### `workspaceFiles []string`
150
151 workspaceFiles configures the set of globs that match files defining the
152 logical build of the current workspace. Any on-disk changes to any files
153 matching a glob specified here will trigger a reload of the workspace.
154
155 This setting need only be customized in environments with a custom
156 GOPACKAGESDRIVER.
157
158 Default: `[]`.
159
160 <a id='formatting'></a>
161 ## Formatting
162
163 <a id='local'></a>
164 ### `local string`
165
166 local is the equivalent of the `goimports -local` flag, which puts
167 imports beginning with this string after third-party packages. It should
168 be the prefix of the import path whose imports should be grouped
169 separately.
170
171 It is used when tidying imports (during an LSP Organize
172 Imports request) or when inserting new ones (for example,
173 during completion); an LSP Formatting request merely sorts the
174 existing imports.
175
176 Default: `""`.
177
178 <a id='gofumpt'></a>
179 ### `gofumpt bool`
180
181 gofumpt indicates if we should run gofumpt formatting.
182
183 Default: `false`.
184
185 <a id='ui'></a>
186 ## UI
187
188 <a id='codelenses'></a>
189 ### `codelenses map[enum]bool`
190
191 codelenses overrides the enabled/disabled state of each of gopls'
192 sources of [Code Lenses](codelenses.md).
193
194 Example Usage:
195
196 ```json5
197 "gopls": {
198 ...
199 "codelenses": {
200 "generate": false, // Don't show the `go generate` lens.
201 }
202 ...
203 }
204 ```
205
206 Default: `{"generate":true,"regenerate_cgo":true,"run_govulncheck":true,"tidy":true,"upgrade_dependency":true,"vendor":true}`.
207
208 <a id='semanticTokens'></a>
209 ### `semanticTokens bool`
210
211 **This setting is experimental and may be deleted.**
212
213 semanticTokens determines whether gopls will return a
214 SemanticTokensProvider at initialization, or respond
215 to requests for semantic tokens.
216
217 This setting being `false` won't necessary disable the client's calls
218 for semantic tokens. If you want that, it would need to be configured in
219 the client. For example, in VSCode, this would disable all Go semantic
220 token calls to the LSP server:
221
222 ```json5
223 "[go]": {
224 "editor.semanticHighlighting.enabled": false,
225 }
226 ```
227
228 Default: `false`.
229
230 <a id='noSemanticString'></a>
231 ### `noSemanticString bool`
232
233 **This setting is experimental and may be deleted.**
234
235 noSemanticString turns off the sending of the semantic token 'string'
236
237 Deprecated: Use SemanticTokenTypes["string"] = false instead. See
238 golang/vscode-go#3632
239
240 Default: `false`.
241
242 <a id='noSemanticNumber'></a>
243 ### `noSemanticNumber bool`
244
245 **This setting is experimental and may be deleted.**
246
247 noSemanticNumber turns off the sending of the semantic token 'number'
248
249 Deprecated: Use SemanticTokenTypes["number"] = false instead. See
250 golang/vscode-go#3632.
251
252 Default: `false`.
253
254 <a id='semanticTokenTypes'></a>
255 ### `semanticTokenTypes map[string]bool`
256
257 **This setting is experimental and may be deleted.**
258
259 semanticTokenTypes configures the semantic token types. It allows
260 disabling types by setting each value to false.
261 By default, all types are enabled.
262
263 Default: `{}`.
264
265 <a id='semanticTokenModifiers'></a>
266 ### `semanticTokenModifiers map[string]bool`
267
268 **This setting is experimental and may be deleted.**
269
270 semanticTokenModifiers configures the semantic token modifiers. It allows
271 disabling modifiers by setting each value to false.
272 By default, all modifiers are enabled.
273
274 Default: `{}`.
275
276 <a id='newGoFileHeader'></a>
277 ### `newGoFileHeader bool`
278
279 newGoFileHeader enables automatic insertion of the copyright comment
280 and package declaration in a newly created Go file.
281
282 Default: `true`.
283
284 <a id='renameMovesSubpackages'></a>
285 ### `renameMovesSubpackages bool`
286
287 **This setting is experimental and may be deleted.**
288
289 renameMovesSubpackages enables Rename operations on packages to
290 move subdirectories of the target package.
291
292 Default: `false`.
293
294 <a id='completion'></a>
295 ## Completion
296
297 <a id='usePlaceholders'></a>
298 ### `usePlaceholders bool`
299
300 placeholders enables placeholders for function parameters or struct
301 fields in completion responses.
302
303 Default: `false`.
304
305 <a id='completionBudget'></a>
306 ### `completionBudget time.Duration`
307
308 **This setting is for debugging purposes only.**
309
310 completionBudget is the soft latency goal for completion requests. Most
311 requests finish in a couple milliseconds, but in some cases deep
312 completions can take much longer. As we use up our budget we
313 dynamically reduce the search scope to ensure we return timely
314 results. Zero means unlimited.
315
316 Default: `"100ms"`.
317
318 <a id='matcher'></a>
319 ### `matcher enum`
320
321 **This is an advanced setting and should not be configured by most `gopls` users.**
322
323 matcher sets the algorithm that is used when calculating completion
324 candidates.
325
326 Must be one of:
327
328 * `"CaseInsensitive"`
329 * `"CaseSensitive"`
330 * `"Fuzzy"`
331
332 Default: `"Fuzzy"`.
333
334 <a id='experimentalPostfixCompletions'></a>
335 ### `experimentalPostfixCompletions bool`
336
337 **This setting is experimental and may be deleted.**
338
339 experimentalPostfixCompletions enables artificial method snippets
340 such as "someSlice.sort!".
341
342 Default: `true`.
343
344 <a id='completeFunctionCalls'></a>
345 ### `completeFunctionCalls bool`
346
347 completeFunctionCalls enables function call completion.
348
349 When completing a statement, or when a function return type matches the
350 expected of the expression being completed, completion may suggest call
351 expressions (i.e. may include parentheses).
352
353 Default: `true`.
354
355 <a id='diagnostic'></a>
356 ## Diagnostic
357
358 <a id='analyses'></a>
359 ### `analyses map[string]bool`
360
361 analyses specify analyses that the user would like to enable or disable.
362 A map of the names of analysis passes that should be enabled/disabled.
363 A full list of analyzers that gopls uses can be found in
364 [analyzers.md](https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md).
365
366 Example Usage:
367
368 ```json5
369 ...
370 "analyses": {
371 "unreachable": false, // Disable the unreachable analyzer.
372 "unusedvariable": true // Enable the unusedvariable analyzer.
373 }
374 ...
375 ```
376
377 Default: `{}`.
378
379 <a id='staticcheck'></a>
380 ### `staticcheck bool`
381
382 **This setting is experimental and may be deleted.**
383
384 staticcheck configures the default set of analyses staticcheck.io.
385 These analyses are documented on
386 [Staticcheck's website](https://staticcheck.io/docs/checks/).
387
388 The "staticcheck" option has three values:
389 - false: disable all staticcheck analyzers
390 - true: enable all staticcheck analyzers
391 - unset: enable a subset of staticcheck analyzers
392 selected by gopls maintainers for runtime efficiency
393 and analytic precision.
394
395 Regardless of this setting, individual analyzers can be
396 selectively enabled or disabled using the `analyses` setting.
397
398 Default: `false`.
399
400 <a id='staticcheckProvided'></a>
401 ### `staticcheckProvided bool`
402
403 **This setting is experimental and may be deleted.**
404
405
406 Default: `false`.
407
408 <a id='annotations'></a>
409 ### `annotations map[enum]bool`
410
411 annotations specifies the various kinds of compiler
412 optimization details that should be reported as diagnostics
413 when enabled for a package by the "Toggle compiler
414 optimization details" (`gopls.gc_details`) command.
415
416 (Some users care only about one kind of annotation in their
417 profiling efforts. More importantly, in large packages, the
418 number of annotations can sometimes overwhelm the user
419 interface and exceed the per-file diagnostic limit.)
420
421 TODO(adonovan): rename this field to CompilerOptDetail.
422
423 Each enum must be one of:
424
425 * `"bounds"` controls bounds checking diagnostics.
426 * `"escape"` controls diagnostics about escape choices.
427 * `"inline"` controls diagnostics about inlining choices.
428 * `"nil"` controls nil checks.
429
430 Default: `{"bounds":true,"escape":true,"inline":true,"nil":true}`.
431
432 <a id='vulncheck'></a>
433 ### `vulncheck enum`
434
435 **This setting is experimental and may be deleted.**
436
437 vulncheck enables vulnerability scanning.
438
439 Must be one of:
440
441 * `"Imports"`: In Imports mode, `gopls` will report vulnerabilities that affect packages
442 directly and indirectly used by the analyzed main module.
443 * `"Off"`: Disable vulnerability analysis.
444 * `"Prompt"`: Vulncheck can be triggered via prompt.
445
446 Default: `"Prompt"`.
447
448 <a id='diagnosticsDelay'></a>
449 ### `diagnosticsDelay time.Duration`
450
451 **This is an advanced setting and should not be configured by most `gopls` users.**
452
453 diagnosticsDelay controls the amount of time that gopls waits
454 after the most recent file modification before computing deep diagnostics.
455 Simple diagnostics (parsing and type-checking) are always run immediately
456 on recently modified packages.
457
458 This option must be set to a valid duration string, for example `"250ms"`.
459
460 Default: `"1s"`.
461
462 <a id='diagnosticsTrigger'></a>
463 ### `diagnosticsTrigger enum`
464
465 **This setting is experimental and may be deleted.**
466
467 diagnosticsTrigger controls when to run diagnostics.
468
469 Must be one of:
470
471 * `"Edit"`: Trigger diagnostics on file edit and save. (default)
472 * `"Save"`: Trigger diagnostics only on file save. Events like initial workspace load
473 or configuration change will still trigger diagnostics.
474
475 Default: `"Edit"`.
476
477 <a id='analysisProgressReporting'></a>
478 ### `analysisProgressReporting bool`
479
480 analysisProgressReporting controls whether gopls sends progress
481 notifications when construction of its index of analysis facts is taking a
482 long time. Cancelling these notifications will cancel the indexing task,
483 though it will restart after the next change in the workspace.
484
485 When a package is opened for the first time and heavyweight analyses such as
486 staticcheck are enabled, it can take a while to construct the index of
487 analysis facts for all its dependencies. The index is cached in the
488 filesystem, so subsequent analysis should be faster.
489
490 Default: `true`.
491
492 <a id='documentation'></a>
493 ## Documentation
494
495 <a id='hoverKind'></a>
496 ### `hoverKind enum`
497
498 hoverKind controls the information that appears in the hover text.
499 SingleLine is intended for use only by authors of editor plugins.
500
501 Must be one of:
502
503 * `"FullDocumentation"`
504 * `"NoDocumentation"`
505 * `"SingleLine"`
506 * `"Structured"` is a misguided experimental setting that returns a JSON
507 hover format. This setting should not be used, as it will be removed in a
508 future release of gopls.
509 * `"SynopsisDocumentation"`
510
511 Default: `"FullDocumentation"`.
512
513 <a id='linkTarget'></a>
514 ### `linkTarget string`
515
516 linkTarget is the base URL for links to Go package
517 documentation returned by LSP operations such as Hover and
518 DocumentLinks and in the CodeDescription field of each
519 Diagnostic.
520
521 It might be one of:
522
523 * `"godoc.org"`
524 * `"pkg.go.dev"`
525
526 If company chooses to use its own `godoc.org`, its address can be used as well.
527
528 Modules matching the GOPRIVATE environment variable will not have
529 documentation links in hover.
530
531 Default: `"pkg.go.dev"`.
532
533 <a id='linksInHover'></a>
534 ### `linksInHover enum`
535
536 linksInHover controls the presence of documentation links in hover markdown.
537
538 Must be one of:
539
540 * false: do not show links
541 * true: show links to the `linkTarget` domain
542 * `"gopls"`: show links to gopls' internal documentation viewer
543
544 Default: `true`.
545
546 <a id='inlayhint'></a>
547 ## Inlayhint
548
549 <a id='hints'></a>
550 ### `hints map[enum]bool`
551
552 **This setting is experimental and may be deleted.**
553
554 hints specify inlay hints that users want to see. A full list of hints
555 that gopls uses can be found in
556 [inlayHints.md](https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.md).
557
558 Default: `{}`.
559
560 <a id='navigation'></a>
561 ## Navigation
562
563 <a id='importShortcut'></a>
564 ### `importShortcut enum`
565
566 importShortcut specifies whether import statements should link to
567 documentation or go to definitions.
568
569 Must be one of:
570
571 * `"Both"`
572 * `"Definition"`
573 * `"Link"`
574
575 Default: `"Both"`.
576
577 <a id='symbolMatcher'></a>
578 ### `symbolMatcher enum`
579
580 **This is an advanced setting and should not be configured by most `gopls` users.**
581
582 symbolMatcher sets the algorithm that is used when finding workspace symbols.
583
584 Must be one of:
585
586 * `"CaseInsensitive"`
587 * `"CaseSensitive"`
588 * `"FastFuzzy"`
589 * `"Fuzzy"`
590
591 Default: `"FastFuzzy"`.
592
593 <a id='symbolStyle'></a>
594 ### `symbolStyle enum`
595
596 **This is an advanced setting and should not be configured by most `gopls` users.**
597
598 symbolStyle controls how symbols are qualified in symbol responses.
599
600 Example Usage:
601
602 ```json5
603 "gopls": {
604 ...
605 "symbolStyle": "Dynamic",
606 ...
607 }
608 ```
609
610 Must be one of:
611
612 * `"Dynamic"` uses whichever qualifier results in the highest scoring
613 match for the given symbol query. Here a "qualifier" is any "/" or "."
614 delimited suffix of the fully qualified symbol. i.e. "to/pkg.Foo.Field" or
615 just "Foo.Field".
616 * `"Full"` is fully qualified symbols, i.e.
617 "path/to/pkg.Foo.Field".
618 * `"Package"` is package qualified symbols i.e.
619 "pkg.Foo.Field".
620
621 Default: `"Dynamic"`.
622
623 <a id='symbolScope'></a>
624 ### `symbolScope enum`
625
626 symbolScope controls which packages are searched for workspace/symbol
627 requests. When the scope is "workspace", gopls searches only workspace
628 packages. When the scope is "all", gopls searches all loaded packages,
629 including dependencies and the standard library.
630
631 Must be one of:
632
633 * `"all"` matches symbols in any loaded package, including
634 dependencies.
635 * `"workspace"` matches symbols in workspace packages only.
636
637 Default: `"all"`.
638
639 <a id='fileWatcher'></a>
640 ### `fileWatcher enum`
641
642 **This setting is experimental and may be deleted.**
643
644 fileWatcher specifies the server-side file watching strategy used by gopls.
645
646 By default, this is set to "off", meaning gopls relies exclusively on the
647 language client (e.g., the editor) to send file change notifications.
648
649 Available options:
650 - "off" : Client-driven watching (default)
651 - "fsnotify" : OS-level event notifications
652 - "poll" : Periodic directory scanning
653
654 Must be one of:
655
656 * `"fsnotify"`
657 * `"off"`
658 * `"poll"`
659
660 Default: `"off"`.
661
662 <a id='maxFileCacheBytes'></a>
663 ### `maxFileCacheBytes int64`
664
665 **This setting is experimental and may be deleted.**
666
667 maxFileCacheBytes sets a soft limit on the file cache size in bytes.
668 If zero, the default budget is used.
669
670 The cache may temporarily use more than this amount.
671 Also, this parameter limits file contents; disk block usage
672 as measured by du(1) may be significantly higher.
673
674 Default: `0`.
675
676 <a id='verboseOutput'></a>
677 ### `verboseOutput bool`
678
679 **This setting is for debugging purposes only.**
680
681 verboseOutput enables additional debug logging.
682
683 Default: `false`.
684
685 <!-- END User: DO NOT MANUALLY EDIT THIS SECTION -->