diff --git a/docs/settings.md b/docs/settings.md index 1409958a55..a9a6a63550 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -577,31 +577,23 @@ env adds environment variables to external commands run by `gopls`, most notably ### `build.expandWorkspaceToModule` -(Experimental) 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. +(Experimental) expandWorkspaceToModule determines which packages are considered +"workspace packages" when the workspace is using modules. + +Workspace packages affect the scope of workspace-wide operations. Notably, +gopls diagnoses all packages considered to be part of the workspace after +every keystroke, so by setting "ExpandWorkspaceToModule" to false, and +opening a nested workspace directory, you can reduce the amount of work +gopls has to do to keep your workspace up to date. Default: `true` ### `build.memoryMode` -(Experimental) memoryMode controls the tradeoff `gopls` makes between memory usage and -correctness. - -Values other than `Normal` are untested and may break in surprising ways. -
-Allowed Options: - -* `DegradeClosed`: `"DegradeClosed"`: In DegradeClosed mode, `gopls` will collect less information about -packages without open files. As a result, features like Find -References and Rename will miss results in such packages. -* `Normal` +(Experimental) obsolete, no effect -Default: `"Normal"` +Default: `""` ### `build.standaloneTags` standaloneTags specifies a set of build constraints that identify @@ -755,39 +747,39 @@ Example Usage: | `embed` | check //go:embed directive usage
This analyzer checks that the embed package is imported if //go:embed directives are present, providing a suggested fix to add the import if it is missing.
This analyzer also checks that //go:embed directives precede the declaration of a single variable.
Default: `true` | | `errorsas` | report passing non-pointer or non-error values to errors.As
The errorsas analysis reports calls to errors.As where the type of the second argument is not a pointer to a type implementing error.
Default: `true` | | `fieldalignment` | find structs that would use less memory if their fields were sorted
This analyzer find structs that can be rearranged to use less memory, and provides a suggested edit with the most compact order.
Note that there are two different diagnostics reported. One checks struct size, and the other reports "pointer bytes" used. Pointer bytes is how many bytes of the object that the garbage collector has to potentially scan for pointers, for example:
struct { uint32; string }

have 16 pointer bytes because the garbage collector has to scan up through the string's inner pointer.
struct { string; *uint32 }

has 24 pointer bytes because it has to scan further through the *uint32.
struct { string; uint32 }

has 8 because it can stop immediately after the string pointer.
Be aware that the most compact order is not always the most efficient. In rare cases it may cause two variables each updated by its own goroutine to occupy the same CPU cache line, inducing a form of memory contention known as "false sharing" that slows down both goroutines.

Default: `false` | -| `fillreturns` | suggest fixes for errors due to an incorrect number of return values
This checker provides suggested fixes for type errors of the type "wrong number of return values (want %d, got %d)". For example:
func m() (int, string, *bool, error) {
return
}
will turn into
func m() (int, string, *bool, error) {
return 0, "", nil, nil
}

This functionality is similar to https://github.com/sqs/goreturns.

Default: `true` | +| `fillreturns` | suggest fixes for errors due to an incorrect number of return values
This checker provides suggested fixes for type errors of the type "wrong number of return values (want %d, got %d)". For example:
func m() (int, string, *bool, error) {
return
}

will turn into
func m() (int, string, *bool, error) {
return 0, "", nil, nil
}

This functionality is similar to https://github.com/sqs/goreturns.
Default: `true` | | `fillstruct` | note incomplete struct initializations
This analyzer provides diagnostics for any struct literals that do not have any fields initialized. Because the suggested fix for this analysis is expensive to compute, callers should compute it separately, using the SuggestedFix function below.

Default: `true` | | `httpresponse` | check for mistakes using HTTP responses
A common mistake when using the net/http package is to defer a function call to close the http.Response Body before checking the error that determines whether the response is valid:
resp, err := http.Head(url)
defer resp.Body.Close()
if err != nil {
log.Fatal(err)
}
// (defer statement belongs here)

This checker helps uncover latent nil dereference bugs by reporting a diagnostic for such mistakes.
Default: `true` | | `ifaceassert` | detect impossible interface-to-interface type assertions
This checker flags type assertions v.(T) and corresponding type-switch cases in which the static type V of v is an interface that cannot possibly implement the target interface T. This occurs when V and T contain methods with the same name but different signatures. Example:
var v interface {
Read()
}
_ = v.(io.Reader)

The Read method in v has a different signature than the Read method in io.Reader, so this assertion cannot succeed.
Default: `true` | | `infertypeargs` | check for unnecessary type arguments in call expressions
Explicit type arguments may be omitted from call expressions if they can be inferred from function arguments, or from other type arguments:
func f[T any](T) {}


func _() {
f[string]("foo") // string could be inferred
}


Default: `true` | -| `loopclosure` | check references to loop variables from within nested functions
This analyzer reports places where a function literal references the iteration variable of an enclosing loop, and the loop calls the function in such a way (e.g. with go or defer) that it may outlive the loop iteration and possibly observe the wrong value of the variable.
In this example, all the deferred functions run after the loop has completed, so all observe the final value of v.
for _, v := range list {
defer func() {
use(v) // incorrect
}()
}

One fix is to create a new variable for each iteration of the loop:
for _, v := range list {
v := v // new var per iteration
defer func() {
use(v) // ok
}()
}

The next example uses a go statement and has a similar problem. In addition, it has a data race because the loop updates v concurrent with the goroutines accessing it.
for _, v := range elem {
go func() {
use(v) // incorrect, and a data race
}()
}

A fix is the same as before. The checker also reports problems in goroutines started by golang.org/x/sync/errgroup.Group. A hard-to-spot variant of this form is common in parallel tests:
func Test(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
use(test) // incorrect, and a data race
})
}
}

The t.Parallel() call causes the rest of the function to execute concurrent with the loop.
The analyzer reports references only in the last statement, as it is not deep enough to understand the effects of subsequent statements that might render the reference benign. ("Last statement" is defined recursively in compound statements such as if, switch, and select.)
See: https://golang.org/doc/go_faq.html#closures_and_goroutines
Default: `true` | +| `loopclosure` | check references to loop variables from within nested functions
This analyzer reports places where a function literal references the iteration variable of an enclosing loop, and the loop calls the function in such a way (e.g. with go or defer) that it may outlive the loop iteration and possibly observe the wrong value of the variable.
Note: An iteration variable can only outlive a loop iteration in Go versions <=1.21. In Go 1.22 and later, the loop variable lifetimes changed to create a new iteration variable per loop iteration. (See go.dev/issue/60078.)
In this example, all the deferred functions run after the loop has completed, so all observe the final value of v [
for _, v := range list {
defer func() {
use(v) // incorrect
}()
}

One fix is to create a new variable for each iteration of the loop:
for _, v := range list {
v := v // new var per iteration
defer func() {
use(v) // ok
}()
}

After Go version 1.22, the previous two for loops are equivalent and both are correct.
The next example uses a go statement and has a similar problem [
for _, v := range elem {
go func() {
use(v) // incorrect, and a data race
}()
}

A fix is the same as before. The checker also reports problems in goroutines started by golang.org/x/sync/errgroup.Group. A hard-to-spot variant of this form is common in parallel tests:
func Test(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
use(test) // incorrect, and a data race
})
}
}

The t.Parallel() call causes the rest of the function to execute concurrent with the loop [ The analyzer reports references only in the last statement, as it is not deep enough to understand the effects of subsequent statements that might render the reference benign. ("Last statement" is defined recursively in compound statements such as if, switch, and select.)
See: https://golang.org/doc/go_faq.html#closures_and_goroutines
Default: `true` | | `lostcancel` | check cancel func returned by context.WithCancel is called
The cancellation function returned by context.WithCancel, WithTimeout, and WithDeadline must be called or the new context will remain live until its parent context is cancelled. (The background context is never cancelled.)
Default: `true` | | `nilfunc` | check for useless comparisons between functions and nil
A useless comparison is one like f == nil as opposed to f() == nil.
Default: `true` | -| `nilness` | check for redundant or impossible nil comparisons
The nilness checker inspects the control-flow graph of each function in a package and reports nil pointer dereferences, degenerate nil pointers, and panics with nil values. A degenerate comparison is of the form x==nil or x!=nil where x is statically known to be nil or non-nil. These are often a mistake, especially in control flow related to errors. Panics with nil values are checked because they are not detectable by
if r := recover(); r != nil {

This check reports conditions such as:
if f == nil { // impossible condition (f is a function)
}

and:
p := &v
...
if p != nil { // tautological condition
}

and:
if p == nil {
print(*p) // nil dereference
}

and:
if p == nil {
panic(p)
}

Default: `false` | -| `nonewvars` | suggested fixes for "no new vars on left side of :="
This checker provides suggested fixes for type errors of the type "no new vars on left side of :=". For example:
z := 1
z := 2
will turn into
z := 1
z = 2


Default: `true` | -| `noresultvalues` | suggested fixes for unexpected return values
This checker provides suggested fixes for type errors of the type "no result values expected" or "too many return values". For example:
func z() { return nil }
will turn into
func z() { return }


Default: `true` | +| `nilness` | check for redundant or impossible nil comparisons
The nilness checker inspects the control-flow graph of each function in a package and reports nil pointer dereferences, degenerate nil pointers, and panics with nil values. A degenerate comparison is of the form x==nil or x!=nil where x is statically known to be nil or non-nil. These are often a mistake, especially in control flow related to errors. Panics with nil values are checked because they are not detectable by
if r := recover(); r != nil {

This check reports conditions such as:
if f == nil { // impossible condition (f is a function)
}

and:
p := &v
...
if p != nil { // tautological condition
}

and:
if p == nil {
print(*p) // nil dereference
}

and:
if p == nil {
panic(p)
}

Default: `true` | +| `nonewvars` | suggested fixes for "no new vars on left side of :="
This checker provides suggested fixes for type errors of the type "no new vars on left side of :=". For example:
z := 1
z := 2

will turn into
z := 1
z = 2

Default: `true` | +| `noresultvalues` | suggested fixes for unexpected return values
This checker provides suggested fixes for type errors of the type "no result values expected" or "too many return values". For example:
func z() { return nil }

will turn into
func z() { return }

Default: `true` | | `printf` | check consistency of Printf format strings and arguments
The check applies to calls of the formatting functions such as [fmt.Printf] and [fmt.Sprintf], as well as any detected wrappers of those functions.
In this example, the %d format operator requires an integer operand:
fmt.Printf("%d", "hello") // fmt.Printf format %d has arg "hello" of wrong type string

See the documentation of the fmt package for the complete set of format operators and their operand types.
To enable printf checking on a function that is not found by this analyzer's heuristics (for example, because control is obscured by dynamic method calls), insert a bogus call:
func MyPrintf(format string, args ...any) {
if false {
_ = fmt.Sprintf(format, args...) // enable printf checker
}
...
}

The -funcs flag specifies a comma-separated list of names of additional known formatting functions or methods. If the name contains a period, it must denote a specific function using one of the following forms:
dir/pkg.Function
dir/pkg.Type.Method
(*dir/pkg.Type).Method

Otherwise the name is interpreted as a case-insensitive unqualified identifier such as "errorf". Either way, if a listed name ends in f, the function is assumed to be Printf-like, taking a format string before the argument list. Otherwise it is assumed to be Print-like, taking a list of arguments with no format string.
Default: `true` | | `shadow` | check for possible unintended shadowing of variables
This analyzer check for shadowed variables. A shadowed variable is a variable declared in an inner scope with the same name and type as a variable in an outer scope, and where the outer variable is mentioned after the inner one is declared.
(This definition can be refined; the module generates too many false positives and is not yet enabled by default.)
For example:
func BadRead(f *os.File, buf []byte) error {
var err error
for {
n, err := f.Read(buf) // shadows the function variable 'err'
if err != nil {
break // causes return of wrong value
}
foo(buf)
}
return err
}

Default: `false` | | `shift` | check for shifts that equal or exceed the width of the integer
Default: `true` | -| `simplifycompositelit` | check for composite literal simplifications
An array, slice, or map composite literal of the form:
[]T{T{}, T{}}
will be simplified to:
[]T{{}, {}}

This is one of the simplifications that "gofmt -s" applies.
Default: `true` | -| `simplifyrange` | check for range statement simplifications
A range of the form:
for x, _ = range v {...}
will be simplified to:
for x = range v {...}

A range of the form:
for _ = range v {...}
will be simplified to:
for range v {...}

This is one of the simplifications that "gofmt -s" applies.
Default: `true` | -| `simplifyslice` | check for slice simplifications
A slice expression of the form:
s[a:len(s)]
will be simplified to:
s[a:]

This is one of the simplifications that "gofmt -s" applies.
Default: `true` | +| `simplifycompositelit` | check for composite literal simplifications
An array, slice, or map composite literal of the form:
[]T{T{}, T{}}

will be simplified to:
[]T{{}, {}}

This is one of the simplifications that "gofmt -s" applies.
Default: `true` | +| `simplifyrange` | check for range statement simplifications
A range of the form:
for x, _ = range v {...}

will be simplified to:
for x = range v {...}

A range of the form:
for _ = range v {...}

will be simplified to:
for range v {...}

This is one of the simplifications that "gofmt -s" applies.
Default: `true` | +| `simplifyslice` | check for slice simplifications
A slice expression of the form:
s[a:len(s)]

will be simplified to:
s[a:]

This is one of the simplifications that "gofmt -s" applies.
Default: `true` | | `slog` | check for invalid structured logging calls
The slog checker looks for calls to functions from the log/slog package that take alternating key-value pairs. It reports calls where an argument in a key position is neither a string nor a slog.Attr, and where a final key is missing its value. For example,it would report
slog.Warn("message", 11, "k") // slog.Warn arg "11" should be a string or a slog.Attr

and
slog.Info("message", "k1", v1, "k2") // call to slog.Info missing a final value

Default: `true` | | `sortslice` | check the argument type of sort.Slice
sort.Slice requires an argument of a slice type. Check that the interface{} value passed to sort.Slice is actually a slice.
Default: `true` | | `stdmethods` | check signature of methods of well-known interfaces
Sometimes a type may be intended to satisfy an interface but may fail to do so because of a mistake in its method signature. For example, the result of this WriteTo method should be (int64, error), not error, to satisfy io.WriterTo:
type myWriterTo struct{...}
func (myWriterTo) WriteTo(w io.Writer) error { ... }

This check ensures that each method whose name matches one of several well-known interface methods from the standard library has the correct signature for that interface.
Checked method names include:
Format GobEncode GobDecode MarshalJSON MarshalXML
Peek ReadByte ReadFrom ReadRune Scan Seek
UnmarshalJSON UnreadByte UnreadRune WriteByte
WriteTo

Default: `true` | | `stringintconv` | check for string(int) conversions
This checker flags conversions of the form string(x) where x is an integer (but not byte or rune) type. Such conversions are discouraged because they return the UTF-8 representation of the Unicode code point x, and not a decimal string representation of x as one might expect. Furthermore, if x denotes an invalid code point, the conversion cannot be statically rejected.
For conversions that intend on using the code point, consider replacing them with string(rune(x)). Otherwise, strconv.Itoa and its equivalents return the string representation of the value in the desired base.
Default: `true` | | `structtag` | check that struct field tags conform to reflect.StructTag.Get
Also report certain struct tags (json, xml) used with unexported fields.
Default: `true` | -| `stubmethods` | stub methods analyzer
This analyzer generates method stubs for concrete types in order to implement a target interface
Default: `true` | -| `testinggoroutine` | report calls to (*testing.T).Fatal from goroutines started by a test.
Functions that abruptly terminate a test, such as the Fatal, Fatalf, FailNow, and Skip{,f,Now} methods of *testing.T, must be called from the test goroutine itself. This checker detects calls to these functions that occur within a goroutine started by the test. For example:
func TestFoo(t *testing.T) {
go func() {
t.Fatal("oops") // error: (*T).Fatal called from non-test goroutine
}()
}

Default: `true` | +| `stubmethods` | detect missing methods and fix with stub implementations
This analyzer detects type-checking errors due to missing methods in assignments from concrete types to interface types, and offers a suggested fix that will create a set of stub methods so that the concrete type satisfies the interface.
For example, this function will not compile because the value NegativeErr{} does not implement the "error" interface:
func sqrt(x float64) (float64, error) {
if x < 0 {
return 0, NegativeErr{} // error: missing method
}
...
}

type NegativeErr struct{}

This analyzer will suggest a fix to declare this method:
// Error implements error.Error.
func (NegativeErr) Error() string {
panic("unimplemented")
}

(At least, it appears to behave that way, but technically it doesn't use the SuggestedFix mechanism and the stub is created by logic in gopls's source.stub function.)
Default: `true` | +| `testinggoroutine` | report calls to (*testing.T).Fatal from goroutines started by a test
Functions that abruptly terminate a test, such as the Fatal, Fatalf, FailNow, and Skip{,f,Now} methods of *testing.T, must be called from the test goroutine itself. This checker detects calls to these functions that occur within a goroutine started by the test. For example:
func TestFoo(t *testing.T) {
go func() {
t.Fatal("oops") // error: (*T).Fatal called from non-test goroutine
}()
}

Default: `true` | | `tests` | check for common mistaken usages of tests and examples
The tests checker walks Test, Benchmark, Fuzzing and Example functions checking malformed names, wrong signatures and examples documenting non-existent identifiers.
Please see the documentation for package testing in golang.org/pkg/testing for the conventions that are enforced for Tests, Benchmarks, and Examples.
Default: `true` | | `timeformat` | check for calls of (time.Time).Format or time.Parse with 2006-02-01
The timeformat checker looks for time formats with the 2006-02-01 (yyyy-dd-mm) format. Internationally, "yyyy-dd-mm" does not occur in common calendar date standards, and so it is more likely that 2006-01-02 (yyyy-mm-dd) was intended.
Default: `true` | -| `undeclaredname` | suggested fixes for "undeclared name: <>"
This checker provides suggested fixes for type errors of the type "undeclared name: <>". It will either insert a new statement, such as:
"<> := "
or a new function declaration, such as:
func <>(inferred parameters) {
panic("implement me!")
}

Default: `true` | +| `undeclaredname` | suggested fixes for "undeclared name: <>"
This checker provides suggested fixes for type errors of the type "undeclared name: <>". It will either insert a new statement, such as:
<> :=

or a new function declaration, such as:
func <>(inferred parameters) {
panic("implement me!")
}

Default: `true` | | `unmarshal` | report passing non-pointer or non-interface values to unmarshal
The unmarshal analysis reports calls to functions such as json.Unmarshal in which the argument type is not a pointer or an interface.
Default: `true` | | `unreachable` | check for unreachable code
The unreachable analyzer finds statements that execution can never reach because they are preceded by an return statement, a call to panic, an infinite loop, or similar constructs.
Default: `true` | | `unsafeptr` | check for invalid conversions of uintptr to unsafe.Pointer
The unsafeptr analyzer reports likely incorrect uses of unsafe.Pointer to convert integers to pointers. A conversion from uintptr to unsafe.Pointer is invalid if it implies that there is a uintptr-typed word in memory that holds a pointer value, because that word will be invisible to stack copying and to the garbage collector.
Default: `true` | | `unusedparams` | check for unused parameters of functions
The unusedparams analyzer checks functions to see if there are any parameters that are not being used.
To reduce false positives it ignores: - methods - parameters that do not have a name or have the name '_' (the blank identifier) - functions in test files - functions with empty bodies or those with just a return stmt
Default: `false` | | `unusedresult` | check for unused results of calls to some functions
Some functions like fmt.Errorf return a result and have no side effects, so it is always a mistake to discard the result. Other functions may return an error that must not be ignored, or a cleanup operation that must be called. This analyzer reports calls to functions like these when the result of the call is ignored.
The set of functions may be controlled using flags.
Default: `true` | -| `unusedvariable` | check for unused variables
The unusedvariable analyzer suggests fixes for unused variables errors.

Default: `false` | +| `unusedvariable` | check for unused variables and suggest fixes
Default: `false` | | `unusedwrite` | checks for unused writes
The analyzer reports instances of writes to struct fields and arrays that are never read. Specifically, when a struct object or an array is copied, its elements are copied implicitly by the compiler, and any element write to this copy does nothing with the original object.
For example:
type T struct { x int }

func f(input []T) {
for i, v := range input { // v is a copy
v.x = i // unused write to field x
}
}

Another example is about non-pointer receiver:
type T struct { x int }

func (t T) f() {  // t is a copy
t.x = i // unused write to field x
}

Default: `false` | | `useany` | check for constraints that could be simplified to "any"
Default: `false` | ### `ui.diagnostic.analysisProgressReporting` @@ -826,6 +818,18 @@ This option must be set to a valid duration string, for example `"250ms"`. Default: `"1s"` +### `ui.diagnostic.diagnosticsTrigger` + +(Experimental) diagnosticsTrigger controls when to run diagnostics. +
+Allowed Options: + +* `Edit`: `"Edit"`: Trigger diagnostics on file edit and save. (default) +* `Save`: `"Save"`: Trigger diagnostics only on file save. Events like initial workspace load +or configuration change will still trigger diagnostics. + + +Default: `"Edit"` ### `ui.diagnostic.staticcheck` (Experimental) staticcheck enables additional analyses from staticcheck.io. diff --git a/package.json b/package.json index a3b09fd1e3..a54fa6af99 100644 --- a/package.json +++ b/package.json @@ -1978,22 +1978,14 @@ }, "build.expandWorkspaceToModule": { "type": "boolean", - "markdownDescription": "(Experimental) expandWorkspaceToModule instructs `gopls` to adjust the scope of the\nworkspace to find the best available module root. `gopls` first looks for\na go.mod file in any parent directory of the workspace folder, expanding\nthe scope to that directory if it exists. If no viable parent directory is\nfound, gopls will check if there is exactly one child directory containing\na go.mod file, narrowing the scope to that directory if it exists.\n", + "markdownDescription": "(Experimental) expandWorkspaceToModule determines which packages are considered\n\"workspace packages\" when the workspace is using modules.\n\nWorkspace packages affect the scope of workspace-wide operations. Notably,\ngopls diagnoses all packages considered to be part of the workspace after\nevery keystroke, so by setting \"ExpandWorkspaceToModule\" to false, and\nopening a nested workspace directory, you can reduce the amount of work\ngopls has to do to keep your workspace up to date.\n", "default": true, "scope": "resource" }, "build.memoryMode": { "type": "string", - "markdownDescription": "(Experimental) memoryMode controls the tradeoff `gopls` makes between memory usage and\ncorrectness.\n\nValues other than `Normal` are untested and may break in surprising ways.\n", - "enum": [ - "DegradeClosed", - "Normal" - ], - "markdownEnumDescriptions": [ - "`\"DegradeClosed\"`: In DegradeClosed mode, `gopls` will collect less information about\npackages without open files. As a result, features like Find\nReferences and Rename will miss results in such packages.\n", - "" - ], - "default": "Normal", + "markdownDescription": "(Experimental) obsolete, no effect\n", + "default": "", "scope": "resource" }, "build.standaloneTags": { @@ -2176,7 +2168,7 @@ }, "deprecated": { "type": "boolean", - "markdownDescription": "check for use of deprecated identifiers\n\nThe deprecated analyzer looks for deprecated symbols and package imports.\n\nSee https://go.dev/wiki/Deprecated to learn about Go's convention\nfor documenting and signaling deprecated identifiers.", + "markdownDescription": "check for use of deprecated identifiers\n\nThe deprecated analyzer looks for deprecated symbols and package\nimports.\n\nSee https://go.dev/wiki/Deprecated to learn about Go's convention\nfor documenting and signaling deprecated identifiers.", "default": true }, "directive": { @@ -2201,7 +2193,7 @@ }, "fillreturns": { "type": "boolean", - "markdownDescription": "suggest fixes for errors due to an incorrect number of return values\n\nThis checker provides suggested fixes for type errors of the\ntype \"wrong number of return values (want %d, got %d)\". For example:\n\tfunc m() (int, string, *bool, error) {\n\t\treturn\n\t}\nwill turn into\n\tfunc m() (int, string, *bool, error) {\n\t\treturn 0, \"\", nil, nil\n\t}\n\nThis functionality is similar to https://github.com/sqs/goreturns.\n", + "markdownDescription": "suggest fixes for errors due to an incorrect number of return values\n\nThis checker provides suggested fixes for type errors of the\ntype \"wrong number of return values (want %d, got %d)\". For example:\n\n\tfunc m() (int, string, *bool, error) {\n\t\treturn\n\t}\n\nwill turn into\n\n\tfunc m() (int, string, *bool, error) {\n\t\treturn 0, \"\", nil, nil\n\t}\n\nThis functionality is similar to https://github.com/sqs/goreturns.", "default": true }, "fillstruct": { @@ -2226,7 +2218,7 @@ }, "loopclosure": { "type": "boolean", - "markdownDescription": "check references to loop variables from within nested functions\n\nThis analyzer reports places where a function literal references the\niteration variable of an enclosing loop, and the loop calls the function\nin such a way (e.g. with go or defer) that it may outlive the loop\niteration and possibly observe the wrong value of the variable.\n\nIn this example, all the deferred functions run after the loop has\ncompleted, so all observe the final value of v.\n\n\tfor _, v := range list {\n\t defer func() {\n\t use(v) // incorrect\n\t }()\n\t}\n\nOne fix is to create a new variable for each iteration of the loop:\n\n\tfor _, v := range list {\n\t v := v // new var per iteration\n\t defer func() {\n\t use(v) // ok\n\t }()\n\t}\n\nThe next example uses a go statement and has a similar problem.\nIn addition, it has a data race because the loop updates v\nconcurrent with the goroutines accessing it.\n\n\tfor _, v := range elem {\n\t go func() {\n\t use(v) // incorrect, and a data race\n\t }()\n\t}\n\nA fix is the same as before. The checker also reports problems\nin goroutines started by golang.org/x/sync/errgroup.Group.\nA hard-to-spot variant of this form is common in parallel tests:\n\n\tfunc Test(t *testing.T) {\n\t for _, test := range tests {\n\t t.Run(test.name, func(t *testing.T) {\n\t t.Parallel()\n\t use(test) // incorrect, and a data race\n\t })\n\t }\n\t}\n\nThe t.Parallel() call causes the rest of the function to execute\nconcurrent with the loop.\n\nThe analyzer reports references only in the last statement,\nas it is not deep enough to understand the effects of subsequent\nstatements that might render the reference benign.\n(\"Last statement\" is defined recursively in compound\nstatements such as if, switch, and select.)\n\nSee: https://golang.org/doc/go_faq.html#closures_and_goroutines", + "markdownDescription": "check references to loop variables from within nested functions\n\nThis analyzer reports places where a function literal references the\niteration variable of an enclosing loop, and the loop calls the function\nin such a way (e.g. with go or defer) that it may outlive the loop\niteration and possibly observe the wrong value of the variable.\n\nNote: An iteration variable can only outlive a loop iteration in Go versions <=1.21.\nIn Go 1.22 and later, the loop variable lifetimes changed to create a new\niteration variable per loop iteration. (See go.dev/issue/60078.)\n\nIn this example, all the deferred functions run after the loop has\ncompleted, so all observe the final value of v [\"\n\nThis checker provides suggested fixes for type errors of the\ntype \"undeclared name: <>\". It will either insert a new statement,\nsuch as:\n\n\"<> := \"\n\nor a new function declaration, such as:\n\nfunc <>(inferred parameters) {\n\tpanic(\"implement me!\")\n}\n", + "markdownDescription": "suggested fixes for \"undeclared name: <>\"\n\nThis checker provides suggested fixes for type errors of the\ntype \"undeclared name: <>\". It will either insert a new statement,\nsuch as:\n\n\t<> :=\n\nor a new function declaration, such as:\n\n\tfunc <>(inferred parameters) {\n\t\tpanic(\"implement me!\")\n\t}", "default": true }, "unmarshal": { @@ -2361,7 +2353,7 @@ }, "unusedvariable": { "type": "boolean", - "markdownDescription": "check for unused variables\n\nThe unusedvariable analyzer suggests fixes for unused variables errors.\n", + "markdownDescription": "check for unused variables and suggest fixes", "default": false }, "unusedwrite": { @@ -2415,6 +2407,20 @@ "default": "1s", "scope": "resource" }, + "ui.diagnostic.diagnosticsTrigger": { + "type": "string", + "markdownDescription": "(Experimental) diagnosticsTrigger controls when to run diagnostics.\n", + "enum": [ + "Edit", + "Save" + ], + "markdownEnumDescriptions": [ + "`\"Edit\"`: Trigger diagnostics on file edit and save. (default)\n", + "`\"Save\"`: Trigger diagnostics only on file save. Events like initial workspace load\nor configuration change will still trigger diagnostics.\n" + ], + "default": "Edit", + "scope": "resource" + }, "ui.diagnostic.staticcheck": { "type": "boolean", "markdownDescription": "(Experimental) staticcheck enables additional analyses from staticcheck.io.\nThese analyses are documented on\n[Staticcheck's website](https://staticcheck.io/docs/checks/).\n",