From 55843514ed4e4fe0232a69a9422156a5ab5ba5fc Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Thu, 20 Jun 2024 12:52:19 -0400 Subject: [PATCH] extension/tools/goplssetting: update to work with gopls v0.16.0 settings Temporarily map "any" to "boolean" until CL 593656 is released. For golang/go#68057 Change-Id: Id134337269b26b9a9ddb546c63f645996d3c3c83 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/593678 Reviewed-by: Alan Donovan Reviewed-by: Robert Findley Commit-Queue: Hyang-Ah Hana Kim kokoro-CI: kokoro --- docs/settings.md | 53 ++++++++++---------- extension/package.json | 49 ++++++++++-------- extension/tools/goplssetting/goplssetting.go | 4 +- 3 files changed, 58 insertions(+), 48 deletions(-) diff --git a/docs/settings.md b/docs/settings.md index 468bfb3a..2ab5fae0 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -530,13 +530,6 @@ downloads rather than requiring user action. This option will eventually be removed. -Default: `false` -### `build.allowModfileModifications` - -(Experimental) allowModfileModifications disables -mod=readonly, allowing imports from -out-of-scope modules. This option will eventually be removed. - - Default: `false` ### `build.buildFlags` @@ -638,10 +631,8 @@ separately. Default: `""` ### `ui.codelenses` -codelenses overrides the enabled/disabled state of code lenses. See the -"Code Lenses" section of the -[Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#code-lenses) -for the list of supported lenses. +codelenses overrides the enabled/disabled state of each of gopls' +sources of [Code Lenses](codelenses.md). Example Usage: @@ -658,14 +649,14 @@ Example Usage: | Properties | Description | | --- | --- | -| `gc_details` | Toggle the calculation of gc annotations.
Default: `false` | -| `generate` | Runs `go generate` for a given directory.
Default: `true` | -| `regenerate_cgo` | Regenerates cgo definitions.
Default: `true` | -| `run_govulncheck` | Run vulnerability check (`govulncheck`).
Default: `false` | -| `test` | Runs `go test` for a specific set of test or benchmark functions.
Default: `false` | -| `tidy` | Runs `go mod tidy` for a module.
Default: `true` | -| `upgrade_dependency` | Upgrades a dependency in the go.mod file for a module.
Default: `true` | -| `vendor` | Runs `go mod vendor` for a module.
Default: `true` | +| `gc_details` | `"gc_details"`: Toggle display of Go compiler optimization decisions
This codelens source causes the `package` declaration of each file to be annotated with a command to toggle the state of the per-session variable that controls whether optimization decisions from the Go compiler (formerly known as "gc") should be displayed as diagnostics.
Optimization decisions include: - whether a variable escapes, and how escape is inferred; - whether a nil-pointer check is implied or eliminated; - whether a function can be inlined.
TODO(adonovan): this source is off by default because the annotation is annoying and because VS Code has a separate "Toggle gc details" command. Replace it with a Code Action ("Source action...").

Default: `false` | +| `generate` | `"generate"`: Run `go generate`
This codelens source annotates any `//go:generate` comments with commands to run `go generate` in this directory, on all directories recursively beneath this one.
See [Generating code](https://go.dev/blog/generate) for more details.

Default: `true` | +| `regenerate_cgo` | `"regenerate_cgo"`: Re-generate cgo declarations
This codelens source annotates an `import "C"` declaration with a command to re-run the [cgo command](https://pkg.go.dev/cmd/cgo) to regenerate the corresponding Go declarations.
Use this after editing the C code in comments attached to the import, or in C header files included by it.

Default: `true` | +| `run_govulncheck` | `"run_govulncheck"`: Run govulncheck
This codelens source annotates the `module` directive in a go.mod file with a command to run Govulncheck.
[Govulncheck](https://go.dev/blog/vuln) is a static analysis tool that computes the set of functions reachable within your application, including dependencies; queries a database of known security vulnerabilities; and reports any potential problems it finds.

Default: `false` | +| `test` | `"test"`: Run tests and benchmarks
This codelens source annotates each `Test` and `Benchmark` function in a `*_test.go` file with a command to run it.
This source is off by default because VS Code has a client-side custom UI for testing, and because progress notifications are not a great UX for streamed test output. See: - golang/go#67400 for a discussion of this feature. - https://github.com/joaotavora/eglot/discussions/1402 for an alternative approach.

Default: `false` | +| `tidy` | `"tidy"`: Tidy go.mod file
This codelens source annotates the `module` directive in a go.mod file with a command to run [`go mod tidy`](https://go.dev/ref/mod#go-mod-tidy), which ensures that the go.mod file matches the source code in the module.

Default: `true` | +| `upgrade_dependency` | `"upgrade_dependency"`: Update dependencies
This codelens source annotates the `module` directive in a go.mod file with commands to:
- check for available upgrades, - upgrade direct dependencies, and - upgrade all dependencies transitively.

Default: `true` | +| `vendor` | `"vendor"`: Update vendor directory
This codelens source annotates the `module` directive in a go.mod file with a command to run [`go mod vendor`](https://go.dev/ref/mod#go-mod-vendor), which creates or updates the directory named `vendor` in the module root so that it contains an up-to-date copy of all necessary package dependencies.

Default: `true` | ### `ui.completion.completeFunctionCalls` completeFunctionCalls enables function call completion. @@ -746,24 +737,27 @@ Example Usage: | `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` | +| `framepointer` | report assembly that clobbers the frame pointer before saving it
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.
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: `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)
}

Sometimes the control flow may be quite complex, making bugs hard to spot. In the example below, the err.Error expression is guaranteed to panic because, after the first return, err must be nil. The intervening loop is just a distraction.
...
err := g.Wait()
if err != nil {
return err
}
partialSuccess := false
for _, err := range errs {
if err == nil {
partialSuccess = true
break
}
}
if partialSuccess {
reportStatus(StatusMessage{
Code: code.ERROR,
Detail: err.Error(), // "nil dereference in dynamic method call"
})
return nil
}

...
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` | +| `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 such as [log.Printf]. It reports a variety of mistakes such as syntax errors in the format string and mismatches (of number and type) between the verbs and their arguments.
See the documentation of the fmt package for the complete set of format operators and their operand types.
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` | +| `sigchanyzer` | check for unbuffered channel of os.Signal
This checker reports call expression of the form
signal.Notify(c <-chan os.Signal, sig ...os.Signal),

where c is an unbuffered channel, which can be at risk of missing the signal.
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` | +| `stdversion` | report uses of too-new standard library symbols
The stdversion analyzer reports references to symbols in the standard library that were introduced by a Go release higher than the one in force in the referring file. (Recall that the file's Go version is defined by the 'go' directive its module's go.mod file, or by a "//go:build go1.X" build tag at the top of the file.)
The analyzer does not report a diagnostic for a reference to a "too new" field or method of a type that is itself "too new", as this may have false positives, for example if fields or methods are accessed through a type alias that is guarded by a Go version constraint.

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` | 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 golang.stub function.)
Default: `true` | @@ -777,7 +771,7 @@ Example Usage: | `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 ensure soundness, it ignores: - "address-taken" functions, that is, functions that are used as a value rather than being called directly; their signatures may be required to conform to a func type. - exported functions or methods, since they may be address-taken in another package. - unexported methods whose name matches an interface method declared in the same package, since the method's signature may be required to conform to the interface type. - functions with empty bodies, or containing just a call to panic. - parameters that are unnamed, or named "_", the blank identifier.
The analyzer suggests a fix of replacing the parameter name by "_", but in such cases a deeper fix can be obtained by invoking the "Refactor: remove unused parameter" code action, which will eliminate the parameter entirely, along with all corresponding arguments at call sites, while taking care to preserve any side effects in the argument expressions; see https://github.com/golang/tools/releases/tag/gopls%2Fv0.14.
Default: `true` | | `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 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` | +| `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: `true` | | `useany` | check for constraints that could be simplified to "any"
Default: `false` | ### `ui.diagnostic.analysisProgressReporting` @@ -869,7 +863,13 @@ documentation links in hover. Default: `"pkg.go.dev"` ### `ui.documentation.linksInHover` -linksInHover toggles the presence of links to documentation in hover. +linksInHover controls the presence of documentation links +in hover markdown. + +Its legal values are: +- `false`, for no links; +- `true`, for links to the `linkTarget` domain; or +- `"gopls"`, for links to gopls' internal documentation viewer. Default: `true` @@ -891,10 +891,9 @@ Default: `"FastFuzzy"` ### `ui.navigation.symbolScope` symbolScope controls which packages are searched for workspace/symbol -requests. The default value, "workspace", searches only workspace -packages. The legacy behavior, "all", causes all loaded packages to be -searched, including dependencies; this is more expensive and may return -unwanted results. +requests. When the scope is "workspace", gopls searches only workspace +packages. When the scope is "all", gopls searches all loaded packages, +including dependencies and the standard library.
Allowed Options: diff --git a/extension/package.json b/extension/package.json index 1de0843f..b8034f99 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1944,12 +1944,6 @@ "default": false, "scope": "resource" }, - "build.allowModfileModifications": { - "type": "boolean", - "markdownDescription": "(Experimental) allowModfileModifications disables -mod=readonly, allowing imports from\nout-of-scope modules. This option will eventually be removed.\n", - "default": false, - "scope": "resource" - }, "build.buildFlags": { "type": "array", "markdownDescription": "buildFlags is the set of flags passed on to the build system when invoked.\nIt is applied to queries like `go list`, which is used when discovering files.\nThe most common use is to set `-tags`.\n\nIf unspecified, values of `go.buildFlags, go.buildTags` will be propagated.\n", @@ -2009,47 +2003,47 @@ }, "ui.codelenses": { "type": "object", - "markdownDescription": "codelenses overrides the enabled/disabled state of code lenses. See the\n\"Code Lenses\" section of the\n[Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#code-lenses)\nfor the list of supported lenses.\n\nExample Usage:\n\n```json5\n\"gopls\": {\n...\n \"codelenses\": {\n \"generate\": false, // Don't show the `go generate` lens.\n \"gc_details\": true // Show a code lens toggling the display of gc's choices.\n }\n...\n}\n```\n", + "markdownDescription": "codelenses overrides the enabled/disabled state of each of gopls'\nsources of [Code Lenses](codelenses.md).\n\nExample Usage:\n\n```json5\n\"gopls\": {\n...\n \"codelenses\": {\n \"generate\": false, // Don't show the `go generate` lens.\n \"gc_details\": true // Show a code lens toggling the display of gc's choices.\n }\n...\n}\n```\n", "scope": "resource", "properties": { "gc_details": { "type": "boolean", - "markdownDescription": "Toggle the calculation of gc annotations.", + "markdownDescription": "`\"gc_details\"`: Toggle display of Go compiler optimization decisions\n\nThis codelens source causes the `package` declaration of\neach file to be annotated with a command to toggle the\nstate of the per-session variable that controls whether\noptimization decisions from the Go compiler (formerly known\nas \"gc\") should be displayed as diagnostics.\n\nOptimization decisions include:\n- whether a variable escapes, and how escape is inferred;\n- whether a nil-pointer check is implied or eliminated;\n- whether a function can be inlined.\n\nTODO(adonovan): this source is off by default because the\nannotation is annoying and because VS Code has a separate\n\"Toggle gc details\" command. Replace it with a Code Action\n(\"Source action...\").\n", "default": false }, "generate": { "type": "boolean", - "markdownDescription": "Runs `go generate` for a given directory.", + "markdownDescription": "`\"generate\"`: Run `go generate`\n\nThis codelens source annotates any `//go:generate` comments\nwith commands to run `go generate` in this directory, on\nall directories recursively beneath this one.\n\nSee [Generating code](https://go.dev/blog/generate) for\nmore details.\n", "default": true }, "regenerate_cgo": { "type": "boolean", - "markdownDescription": "Regenerates cgo definitions.", + "markdownDescription": "`\"regenerate_cgo\"`: Re-generate cgo declarations\n\nThis codelens source annotates an `import \"C\"` declaration\nwith a command to re-run the [cgo\ncommand](https://pkg.go.dev/cmd/cgo) to regenerate the\ncorresponding Go declarations.\n\nUse this after editing the C code in comments attached to\nthe import, or in C header files included by it.\n", "default": true }, "run_govulncheck": { "type": "boolean", - "markdownDescription": "Run vulnerability check (`govulncheck`).", + "markdownDescription": "`\"run_govulncheck\"`: Run govulncheck\n\nThis codelens source annotates the `module` directive in a\ngo.mod file with a command to run Govulncheck.\n\n[Govulncheck](https://go.dev/blog/vuln) is a static\nanalysis tool that computes the set of functions reachable\nwithin your application, including dependencies;\nqueries a database of known security vulnerabilities; and\nreports any potential problems it finds.\n", "default": false }, "test": { "type": "boolean", - "markdownDescription": "Runs `go test` for a specific set of test or benchmark functions.", + "markdownDescription": "`\"test\"`: Run tests and benchmarks\n\nThis codelens source annotates each `Test` and `Benchmark`\nfunction in a `*_test.go` file with a command to run it.\n\nThis source is off by default because VS Code has\na client-side custom UI for testing, and because progress\nnotifications are not a great UX for streamed test output.\nSee:\n- golang/go#67400 for a discussion of this feature.\n- https://github.com/joaotavora/eglot/discussions/1402\n for an alternative approach.\n", "default": false }, "tidy": { "type": "boolean", - "markdownDescription": "Runs `go mod tidy` for a module.", + "markdownDescription": "`\"tidy\"`: Tidy go.mod file\n\nThis codelens source annotates the `module` directive in a\ngo.mod file with a command to run [`go mod\ntidy`](https://go.dev/ref/mod#go-mod-tidy), which ensures\nthat the go.mod file matches the source code in the module.\n", "default": true }, "upgrade_dependency": { "type": "boolean", - "markdownDescription": "Upgrades a dependency in the go.mod file for a module.", + "markdownDescription": "`\"upgrade_dependency\"`: Update dependencies\n\nThis codelens source annotates the `module` directive in a\ngo.mod file with commands to:\n\n- check for available upgrades,\n- upgrade direct dependencies, and\n- upgrade all dependencies transitively.\n", "default": true }, "vendor": { "type": "boolean", - "markdownDescription": "Runs `go mod vendor` for a module.", + "markdownDescription": "`\"vendor\"`: Update vendor directory\n\nThis codelens source annotates the `module` directive in a\ngo.mod file with a command to run [`go mod\nvendor`](https://go.dev/ref/mod#go-mod-vendor), which\ncreates or updates the directory named `vendor` in the\nmodule root so that it contains an up-to-date copy of all\nnecessary package dependencies.\n", "default": true } } @@ -2189,6 +2183,11 @@ "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 }, + "framepointer": { + "type": "boolean", + "markdownDescription": "report assembly that clobbers the frame pointer before saving it", + "default": true + }, "httpresponse": { "type": "boolean", "markdownDescription": "check for mistakes using HTTP responses\n\nA common mistake when using the net/http package is to defer a function\ncall to close the http.Response Body before checking the error that\ndetermines whether the response is valid:\n\n\tresp, err := http.Head(url)\n\tdefer resp.Body.Close()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// (defer statement belongs here)\n\nThis checker helps uncover latent nil dereference bugs by reporting a\ndiagnostic for such mistakes.", @@ -2221,7 +2220,7 @@ }, "nilness": { "type": "boolean", - "markdownDescription": "check for redundant or impossible nil comparisons\n\nThe nilness checker inspects the control-flow graph of each function in\na package and reports nil pointer dereferences, degenerate nil\npointers, and panics with nil values. A degenerate comparison is of the form\nx==nil or x!=nil where x is statically known to be nil or non-nil. These are\noften a mistake, especially in control flow related to errors. Panics with nil\nvalues are checked because they are not detectable by\n\n\tif r := recover(); r != nil {\n\nThis check reports conditions such as:\n\n\tif f == nil { // impossible condition (f is a function)\n\t}\n\nand:\n\n\tp := &v\n\t...\n\tif p != nil { // tautological condition\n\t}\n\nand:\n\n\tif p == nil {\n\t\tprint(*p) // nil dereference\n\t}\n\nand:\n\n\tif p == nil {\n\t\tpanic(p)\n\t}", + "markdownDescription": "check for redundant or impossible nil comparisons\n\nThe nilness checker inspects the control-flow graph of each function in\na package and reports nil pointer dereferences, degenerate nil\npointers, and panics with nil values. A degenerate comparison is of the form\nx==nil or x!=nil where x is statically known to be nil or non-nil. These are\noften a mistake, especially in control flow related to errors. Panics with nil\nvalues are checked because they are not detectable by\n\n\tif r := recover(); r != nil {\n\nThis check reports conditions such as:\n\n\tif f == nil { // impossible condition (f is a function)\n\t}\n\nand:\n\n\tp := &v\n\t...\n\tif p != nil { // tautological condition\n\t}\n\nand:\n\n\tif p == nil {\n\t\tprint(*p) // nil dereference\n\t}\n\nand:\n\n\tif p == nil {\n\t\tpanic(p)\n\t}\n\nSometimes the control flow may be quite complex, making bugs hard\nto spot. In the example below, the err.Error expression is\nguaranteed to panic because, after the first return, err must be\nnil. The intervening loop is just a distraction.\n\n\t...\n\terr := g.Wait()\n\tif err != nil {\n\t\treturn err\n\t}\n\tpartialSuccess := false\n\tfor _, err := range errs {\n\t\tif err == nil {\n\t\t\tpartialSuccess = true\n\t\t\tbreak\n\t\t}\n\t}\n\tif partialSuccess {\n\t\treportStatus(StatusMessage{\n\t\t\tCode: code.ERROR,\n\t\t\tDetail: err.Error(), // \"nil dereference in dynamic method call\"\n\t\t})\n\t\treturn nil\n\t}\n\n...", "default": true }, "nonewvars": { @@ -2236,7 +2235,7 @@ }, "printf": { "type": "boolean", - "markdownDescription": "check consistency of Printf format strings and arguments\n\nThe check applies to calls of the formatting functions such as\n[fmt.Printf] and [fmt.Sprintf], as well as any detected wrappers of\nthose functions.\n\nIn this example, the %d format operator requires an integer operand:\n\n\tfmt.Printf(\"%d\", \"hello\") // fmt.Printf format %d has arg \"hello\" of wrong type string\n\nSee the documentation of the fmt package for the complete set of\nformat operators and their operand types.\n\nTo enable printf checking on a function that is not found by this\nanalyzer's heuristics (for example, because control is obscured by\ndynamic method calls), insert a bogus call:\n\n\tfunc MyPrintf(format string, args ...any) {\n\t\tif false {\n\t\t\t_ = fmt.Sprintf(format, args...) // enable printf checker\n\t\t}\n\t\t...\n\t}\n\nThe -funcs flag specifies a comma-separated list of names of additional\nknown formatting functions or methods. If the name contains a period,\nit must denote a specific function using one of the following forms:\n\n\tdir/pkg.Function\n\tdir/pkg.Type.Method\n\t(*dir/pkg.Type).Method\n\nOtherwise the name is interpreted as a case-insensitive unqualified\nidentifier such as \"errorf\". Either way, if a listed name ends in f, the\nfunction is assumed to be Printf-like, taking a format string before the\nargument list. Otherwise it is assumed to be Print-like, taking a list\nof arguments with no format string.", + "markdownDescription": "check consistency of Printf format strings and arguments\n\nThe check applies to calls of the formatting functions such as\n[fmt.Printf] and [fmt.Sprintf], as well as any detected wrappers of\nthose functions such as [log.Printf]. It reports a variety of\nmistakes such as syntax errors in the format string and mismatches\n(of number and type) between the verbs and their arguments.\n\nSee the documentation of the fmt package for the complete set of\nformat operators and their operand types.", "default": true }, "shadow": { @@ -2249,6 +2248,11 @@ "markdownDescription": "check for shifts that equal or exceed the width of the integer", "default": true }, + "sigchanyzer": { + "type": "boolean", + "markdownDescription": "check for unbuffered channel of os.Signal\n\nThis checker reports call expression of the form\n\n\tsignal.Notify(c <-chan os.Signal, sig ...os.Signal),\n\nwhere c is an unbuffered channel, which can be at risk of missing the signal.", + "default": true + }, "simplifycompositelit": { "type": "boolean", "markdownDescription": "check for composite literal simplifications\n\nAn array, slice, or map composite literal of the form:\n\n\t[]T{T{}, T{}}\n\nwill be simplified to:\n\n\t[]T{{}, {}}\n\nThis is one of the simplifications that \"gofmt -s\" applies.", @@ -2279,6 +2283,11 @@ "markdownDescription": "check signature of methods of well-known interfaces\n\nSometimes a type may be intended to satisfy an interface but may fail to\ndo so because of a mistake in its method signature.\nFor example, the result of this WriteTo method should be (int64, error),\nnot error, to satisfy io.WriterTo:\n\n\ttype myWriterTo struct{...}\n\tfunc (myWriterTo) WriteTo(w io.Writer) error { ... }\n\nThis check ensures that each method whose name matches one of several\nwell-known interface methods from the standard library has the correct\nsignature for that interface.\n\nChecked method names include:\n\n\tFormat GobEncode GobDecode MarshalJSON MarshalXML\n\tPeek ReadByte ReadFrom ReadRune Scan Seek\n\tUnmarshalJSON UnreadByte UnreadRune WriteByte\n\tWriteTo", "default": true }, + "stdversion": { + "type": "boolean", + "markdownDescription": "report uses of too-new standard library symbols\n\nThe stdversion analyzer reports references to symbols in the standard\nlibrary that were introduced by a Go release higher than the one in\nforce in the referring file. (Recall that the file's Go version is\ndefined by the 'go' directive its module's go.mod file, or by a\n\"//go:build go1.X\" build tag at the top of the file.)\n\nThe analyzer does not report a diagnostic for a reference to a \"too\nnew\" field or method of a type that is itself \"too new\", as this may\nhave false positives, for example if fields or methods are accessed\nthrough a type alias that is guarded by a Go version constraint.\n", + "default": true + }, "stringintconv": { "type": "boolean", "markdownDescription": "check for string(int) conversions\n\nThis checker flags conversions of the form string(x) where x is an integer\n(but not byte or rune) type. Such conversions are discouraged because they\nreturn the UTF-8 representation of the Unicode code point x, and not a decimal\nstring representation of x as one might expect. Furthermore, if x denotes an\ninvalid code point, the conversion cannot be statically rejected.\n\nFor conversions that intend on using the code point, consider replacing them\nwith string(rune(x)). Otherwise, strconv.Itoa and its equivalents return the\nstring representation of the value in the desired base.", @@ -2347,7 +2356,7 @@ "unusedwrite": { "type": "boolean", "markdownDescription": "checks for unused writes\n\nThe analyzer reports instances of writes to struct fields and\narrays that are never read. Specifically, when a struct object\nor an array is copied, its elements are copied implicitly by\nthe compiler, and any element write to this copy does nothing\nwith the original object.\n\nFor example:\n\n\ttype T struct { x int }\n\n\tfunc f(input []T) {\n\t\tfor i, v := range input { // v is a copy\n\t\t\tv.x = i // unused write to field x\n\t\t}\n\t}\n\nAnother example is about non-pointer receiver:\n\n\ttype T struct { x int }\n\n\tfunc (t T) f() { // t is a copy\n\t\tt.x = i // unused write to field x\n\t}", - "default": false + "default": true }, "useany": { "type": "boolean", @@ -2443,7 +2452,7 @@ }, "ui.documentation.linksInHover": { "type": "boolean", - "markdownDescription": "linksInHover toggles the presence of links to documentation in hover.\n", + "markdownDescription": "linksInHover controls the presence of documentation links\nin hover markdown.\n\nIts legal values are:\n- `false`, for no links;\n- `true`, for links to the `linkTarget` domain; or\n- `\"gopls\"`, for links to gopls' internal documentation viewer.\n", "default": true, "scope": "resource" }, @@ -2483,7 +2492,7 @@ }, "ui.navigation.symbolScope": { "type": "string", - "markdownDescription": "symbolScope controls which packages are searched for workspace/symbol\nrequests. The default value, \"workspace\", searches only workspace\npackages. The legacy behavior, \"all\", causes all loaded packages to be\nsearched, including dependencies; this is more expensive and may return\nunwanted results.\n", + "markdownDescription": "symbolScope controls which packages are searched for workspace/symbol\nrequests. When the scope is \"workspace\", gopls searches only workspace\npackages. When the scope is \"all\", gopls searches all loaded packages,\nincluding dependencies and the standard library.\n", "enum": [ "all", "workspace" diff --git a/extension/tools/goplssetting/goplssetting.go b/extension/tools/goplssetting/goplssetting.go index c8b75f8c..8442ec8a 100644 --- a/extension/tools/goplssetting/goplssetting.go +++ b/extension/tools/goplssetting/goplssetting.go @@ -349,8 +349,10 @@ func propertyType(t string) string { return "string" case "[]string": return "array" - case "map[string]string", "map[string]bool": + case "map[string]string", "map[string]bool", "map[enum]string", "map[enum]bool": return "object" + case "any": + return "boolean" // TODO(hyangah): change to "" after https://go.dev/cl/593656 is released. } log.Fatalf("unknown type %q", t) return ""