Releases: golang/tools
Release list
gopls v0.23.0
See full release notes: https://go.dev/gopls/release/v0.23.0
Full Changelog: https://github.com/golang/tools/commits/gopls/v0.23.0
gopls v0.22.0
See full release notes: https://go.dev/gopls/release/v0.22.0
Full Changelog: https://github.com/golang/tools/commits/gopls/v0.22.0
gopls v0.21.1
Fixes golang/go#77260, in which references requests were broken when highlighting a function name.
Full Changelog: https://github.com/golang/tools/commits/gopls/v0.21.1
gopls/v0.21.0
See https://go.dev/gopls/release/v0.21.0.
Changes: gopls/v0.20.0...gopls/v0.21.0
Thanks to all who contributed.
Full Changelog: https://github.com/golang/tools/commits/gopls/v0.21.0
gopls/v0.20.0
gopls/v0.19.1
This patch release changes the default value of the importsSource setting: v0.19.0 changed it from goimports to gopls; this release changes it back, due to a bug (#74280).
gopls/v0.19.0
Complete list of issues closed: gopls/v0.19.0 milestone
Configuration Changes
- The
gopls checksubcommand now accepts a-severityflag to set a minimum severity for the diagnostics it reports. By default, the minimum severity is "warning", sogopls checkmay report fewer diagnostics than before. Set-severity=hintto reproduce the previous behavior.
Navigation features
"Implementations" supports signature types (within same package)
The Implementations query reports the correspondence between abstract and concrete types and their methods based on their method sets. Now, it also reports the correspondence between function types, dynamic function calls, and function definitions, based on their signatures.
To use it, invoke an Implementations query on the func token of the definition of a named function, named method, or function literal. Gopls reports the set of function signature types that abstract this function, and the set of dynamic calls through values of such types.
Conversely, an Implementations query on the func token of a signature type, or on the ( paren of a dynamic function call, reports the set of concrete functions that the signature abstracts or that the call dispatches to.
Since a type may be both a function type and a named type with methods (for example, http.HandlerFunc), it may participate in both kinds of Implements queries (method-sets and function signatures). Queries using method-sets should be invoked on the type or method name, and queries using signatures should be invoked on a func or ( token.
Only the local (same-package) algorithm is currently supported. (https://go.dev/issue/56572 tracks the global algorithm.)
"Go to Implementation" reports interface-to-interface relations
The "Go to Implementation" operation now reports relationships between interfaces. Gopls now uses the concreteness of the query type to determine whether a query is "downwards" (from an interface to the types that implement it) or "upwards" (from a concrete type to the interfaces to which it may be assigned). So, for example:
-
implementation(io.Reader)subinterfaces such asio.ReadCloser, and concrete implementations such as*os.File. -
implementation(os.File)includes only interfaces, such asio.Readerandio.ReadCloser.
To request an "upwards" query starting from an interface, for example to find the superinterfaces of io.ReadCloser, use the Type Hierarchy feature described below. (See microsoft/language-server-protocol#2037.)
Support for Type Hierarchy
Gopls now implements the three LSP methods related to the Type Hierarchy viewer: textDocument/prepareTypeHierarchy, typeHierarchy/supertypes, typeHierarchy/subtypes.
In VS Code, select "Show Type Hierarchy" from the context menu to see a tree widget displaying all the supertypes or subtypes of the selected named type.
Editing features
Completion: auto-complete package clause for new Go files
Gopls now automatically adds the appropriate package clause to newly created Go files, so that you can immediately get started writing the interesting part.
It requires client support for workspace/didCreateFiles
New GOMODCACHE index for faster Organize Imports and unimported completions
By default, gopls now builds and maintains a persistent index of packages in the module cache (GOMODCACHE). The operations of Organize Imports and completion of symbols from unimported pacakges are an order of magnitude faster.
To revert to the old behavior, set the importsSource option (whose new default is "gopls") to "goimports". Users who don't want the module cache used at all for imports or completions can change the option to "off".
Analysis features
Most staticcheck analyzers are enabled by default
Slightly more than half of the analyzers in the Staticcheck suite are now enabled by default. This subset has been chosen for precision and efficiency.
Previously, Staticcheck analyzers (all of them) would be run only if the experimental staticcheck boolean option was set to true. This value continues to enable the complete set, and a value of false continues to disable the complete set. Leaving the option unspecified enables the preferred subset of analyzers.
Staticcheck analyzers, like all other analyzers, can be explicitly enabled or disabled using the analyzers configuration setting; this setting now takes precedence over the staticcheck setting, so, regardless of what value of staticcheck you use (true/false/unset), you can make adjustments to your preferred set of analyzers.
VS Code users: if you have configured the Go extension's lintOnSave feature to run the staticcheck executable directly, you may observe duplicate diagnostics: one from the staticcheck process, another from the staticcheck analyzers running within gopls. You may wish to disable lintOnSave, as gopls can run the analyzers more efficiently, and more frequently (even on unsaved files). However, gopls does not honor staticcheck's //lint:ignore directives; see golang/go#74273.
recursiveiter: "inefficient recursive iterator"
A common pitfall when writing a function that returns an iterator (iter.Seq) for a recursive data type is to recursively call the function from its own implementation, leading to a stack of nested coroutines, which is inefficient.
The new recursiveiter analyzer detects such mistakes; see its documentation for details, including tips on how to define simple and efficient recursive iterators.
maprange: "inefficient range over maps.Keys/Values"
The new maprange analyzer detects redundant calls to maps.Keys or maps.Values as the operand of a range loop; maps can of course be ranged over directly. See its documentation for details).
Code transformation features
Rename method receivers
The Rename operation, when applied to the declaration of a method receiver, now also attempts to rename the receivers of all other methods associated with the same named type. Each other receiver that cannot be fully renamed is quietly skipped.
Renaming a use of a method receiver continues to affect only that variable.
type Counter struct { x int }
Rename here to affect only this method
β
func (c *Counter) Inc() { c.x++ }
func (c *Counter) Dec() { c.x++ }
β
Rename here to affect all methods"Eliminate dot import" code action
This code action, available on a dotted import, will offer to replace the import with a regular one and qualify each use of the package with its name.
Add/remove tags from struct fields
Gopls now provides two new code actions, available on an entire struct or some of its fields, that allow you to add and remove struct tags. It adds only 'json' tags with a snakecase naming format, or clears all tags within the selection.
Add tags example:
type Info struct {
LinkTarget string -> LinkTarget string `json:"link_target"`
...
}Inline local variable
The new refactor.inline.variable code action replaces a reference to a local variable by that variable's initializer expression. For example, when applied to s in println(s):
func f(x int) {
s := fmt.Sprintf("+%d", x)
println(s)
}it transforms the code to:
func f(x int) {
s := fmt.Sprintf("+%d", x)
println(fmt.Sprintf("+%d", x))
}Only a single reference is replaced; issue https://go.dev/issue/70085 tracks the feature to "inline all" uses of the variable and eliminate it.
Thank you to our contributors!
@acehinnnqru @adonovan @albfan @aarzilli @ashurbekovz @cuonglm lm @dmitshur @neild @egonelbre @shashank-priyadarshi @firelizzard18 @gopherbot @h9jiang @cuishuang @jakebailey @jba @madelinekalil @karamaru-alpha @danztran @nsrip-dd @pjweinb @findleyr @samthanawalla @seankhliao @tklauser @vikblom @kwjw @xieyuschen
gopls/v0.18.1
This release:
- fixes two bugs in the
minmaxalgorithm of the modernize analyzer that caused it to generate incorrect fixes; and - restores the experimental
hoverKind=structuredconfiguration setting that returned JSON output from Hover requests, as vim-go was relying on it (golang/go#71879).
gopls/v0.18.0
This release contains some small changes to gopls behavior, bug fixes, and new features.
Notably, the new modernize analyzer reports hint diagnostics suggesting ways that Go code could be updated to take advantage of new Go language features and standard library APIs. If hint level diagnostics are noisy in your editor, and you find these diagnostics disruptive, you can disable these analyses by setting:
"analyses": {
"modernize": false
}Configuration Changes
-
The experimental
Structuredvalue for thehoverKindoption is no longer supported. -
The
gc_detailscode lens has been deleted. (It was previously disabled by default.) This functionality is now available through thetoggleCompilerOptDetailscode action, described below, as code actions are better supported than code lenses across a range of clients.VS Code's special "Go: Toggle GC details" command continues to work.
-
The experimental
semanticTokenTypesandsemanticTokenModifiersoptions allow selectively disabling certain types of tokens or token modifiers intextDocument/semanticTokensresponses.These options supersede the
noSemanticStringandnoSemanticTokenNumberoptions, which are now deprecated. Users can instead set"semanticTokenTypes": {"string": false, "number": false}to achieve the same result. For now, gopls still honorsnoSemanticTokenStringandnoSemanticToken, but will stop supporting them in a future release. -
The new
workspaceFilesoption allows configuring glob patterns matching files that define the logical build of the workspace. This option is only needed in environments that use a custom golang.org/x/tools/go/packages driver.
New features
"{Show,Hide} compiler optimization details" code action
This code action, accessible through the "Source Action" menu in VS Code, toggles a per-directory flag that causes Go compiler optimization details to be reported as diagnostics. For example, it indicates which variables escape to the heap, and which array accesses require bounds checks.
New modernize analyzer
Gopls now reports when code could be simplified or clarified by using more modern features of Go, and provides a quick fix to apply the change.
For example, a conditional assignment using an if/else statement may be replaced by a call to the min or max built-in functions added in Go 1.18.
Use this command to apply modernization fixes en masse:
$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
We are aware of a number of minor bugs in the analyzer's fixes. For example, it may sometimes cause a variable or an import to become unused, or may delete comments within a for or if block that is simplified to a library call. The known bugs are low-risk and easy to fix, as they result in a broken build or are obvious during a code review; none cause latent behavior changes. Please report any additional problems you encounter.
New unusedfunc analyzer
Gopls now reports unused functions and methods, giving you near real-time feedback about dead code that may be safely deleted.
Because the analysis is local to each package, only unexported functions and methods are candidates. It may yield false positives for functions referenced only from assembly code, or build-tagged files not part of the current configuration.
(For a more precise analysis that may report unused exported functions too, use the deadcode command.)
New hostport analyzer
With the growing use of IPv6, forming a "host:port" string using fmt.Sprintf("%s:%d") is no longer appropriate because host names may contain colons. Gopls now reports places where a string constructed in this fashion (or with %s for the port) is passed to net.Dial or a related function, and offers a fix to use net.JoinHostPort instead.
Other analyzer changes
- The
unusedvariablequick-fix is now on by default. - The
unusedparamsanalyzer no longer reports finding for generated files.
New gofix analyzer
Gopls now reports when a function call or a use of a constant should be inlined. These diagnostics and the associated code actions are triggered by //go:fix inline directives at the function and constant definitions. See the go:fix proposal for details.
For example, consider a package intmath with a function Square(int) int. Later the more general Pow(int, int) int is introduced, and Square is deprecated in favor of calling Pow with a second argument of 2. The author of intmath can write this:
//go:fix inline
func Square(x int) int { return Pow(x, 2) }
If gopls sees a call to intmath.Square in your code, it will suggest inlining it, and will offer a code action to do so.
The same feature works for constants.
With a constant definition like this:
//go:fix inline
const Ptr = Pointer
gopls will suggest replacing Ptr in your code with Pointer.
Use this command to apply such fixes en masse:
$ go run golang.org/x/tools/gopls/internal/analysis/gofix/cmd/gofix@latest -fix -test ./...
"Implementations" supports generics
At long last, the "Go to Implementations" feature now fully supports generic types and functions (golang/go#59224).
For example, invoking the feature on the interface method Stack.Push below will report the concrete method C[T].Push, and vice versa.
package p
type Stack[T any] interface {
Push(T) error
Pop() (T, bool)
}
type C[T any] struct{}
func (C[T]) Push(t T) error { ... }
func (C[T]) Pop() (T, bool) { ... }
var _ Stack[int] = C[int]{}Extract all occurrences of the same expression under selection
When you have multiple instances of the same expression in a function, you can use this code action to extract it into a variable.
All occurrences of the expression will be replaced with a reference to the new variable.
Improvements to "Definition"
The Definition query now supports additional locations:
- When invoked on a return statement, it reports the location of the function's result variables.
- When invoked on a break, goto, or continue statement, it reports the location of the label, the closing brace of the relevant
block statement, or the start of the relevant loop, respectively.
Improvements to "Hover"
When invoked on a return statement, hover reports the types of the function's result variables.
UX improvements to format strings
"DocumentHighlight"
When your cursor is inside a printf-like function, gopls now highlights the relationship between formatting verbs and arguments as visual cues to differentiate how operands are used in the format string.
fmt.Printf("Hello %s, you scored %d", name, score)If the cursor is either on %s or name, gopls will highlight %s as a write operation, and name as a read operation.
"SemanticHighlight"
Similar to the improvements to DocumentHighlight, gopls also reports formatting verbs as "format" modifier for token type "string" to better distinguish them with other parts of the format string.
fmt.Printf("Hello %s, you scored %d", name, score)%s and %d will have token type "string" and modifier "format".
Bugfixes
A full list of all issues fixed can be found in the gopls/v0.18.0 milestone.
To report a new problem, please file a new issue at https://go.dev/issues/new.
Thank you to our contributors!
@adonovan @cuishuang @dmitshur @ellie-idb @h9jiang @jba @madelinekalil @matloob @prattmic @pjweinb @findleyr @samsalisbury @timothy-king @xzbdmw
gopls/v0.17.1
This release fixes two crashes in gopls@v0.17.0:
- golang/go#70889: a crash in completion of type instances inside a type conversion (found via telemetry).
- golang/go#70927: a crash when a test file has a declaration with signature
func(*error).

