github golang/tools gopls/v0.15.0-pre.3

latest releases: gopls/v0.17.0-pre.1, v0.27.0, v0.26.0...
pre-release9 months ago

These are release notes for a prerelease version of gopls. v0.15.0 will be released soon, but please try the prerelease if you can!

go install golang.org/x/tools/gopls@v0.15.0-pre.3

This release introduces "zero config" gopls, which is a set of heuristics allowing gopls to Do The Right Thing when you open a Go file. We believe this addresses the two largest pain points we hear about from our users: difficulty configuring multi-module repositories, and working on multiple GOOS/GOARCH combinations. However, this is a large change to the way gopls models your workspace, and the dynamic loading/unloading of builds may be surprising in some cases. Your feedback on this new feature is greatly appreciated. See below for more details.

New Features

Simpler workspace configuration and improved build tag support

The headline feature of this release is a rewrite of gopls's logic for associating files with build configurations that enables gopls to give accurate answers when navigating almost any Go source file on your machine.

Most features of gopls rely on type information, which comes not from the file in isolation but depends on the relationship between the file and the other files in its package, and between the package and all its dependencies; this in turn depends on go.mod and go.work files. In effect, gopls needs to decide which go build command--which working directory, package arguments, GOOS, GOARCH, build tags, and so on--would cause each file to be processed by the compiler.

Previous versions of gopls only allowed one build per workspace folder, and users had to be careful to configure the right workspace root and build environment. As a result, users often encountered confusing error messages when they opened the wrong directory, or a file that was tagged for a different operating system or architecture--the dreaded "No packages found" error. This situation was improved by the introduction of go.work files, but still required configuration and a preexisting understanding of the code being edited.

With this release, gopls now allows multiple builds per workspace, and uses heuristics to automatically derive the set of active builds. Gopls will ensure that an active build contains every module with an open file in your workspace, adding new builds and GOOS/GOARCH combinations as needed to cover files that don't match the host operating system or architecture.

For example, suppose we had a repository with three modules: moda, modb, and modc, and a go.work file using modules moda and modb. If we open the files moda/a.go, modb/b.go, moda/a_windows.go, and modc/c.go, gopls will automatically create three builds:

Zero Config

In some cases this may cause gopls to do more work, since gopls is now tracking three builds instead of one. However, the scalability redesign we first announced in v0.12 allows us to avoid most of this work by efficient caching in a persistent store.

So, all gopls' navigation, query, analysis, and refactoring features should work equally well in both files. Notably, you'll see compiler diagnostics for the appropriate build in real time, making it much easier to make changes to cross-platform code.

Preview refactoring edits

Refactoring code actions now support resolving edits. This update enables features like code action previews within VS Code (triggered by Ctrl+Enter).

Refactor preview in VS Code

To take advantage of this new gopls feature, clients must register support via:

{
	"textDocument": {
		"codeAction": {
			"dataSupport": true,
			"resolveSupport": {
				"properties": ["edit"]
			}
		}
	}
}

Analysis & diagnostics

This release includes two new analyzers:

  • The nilness analyzer reports mistakes relating to nil pointers. (In previous releases it was off by default because it was too computationally expensive, but it has since been optimized.)
nilness
  • The unusedparams analyzer reports when a parameter is unused, and offers quick fixes to either rename it to _ or to remove it completely and update all callers. (This analyzer was also previously off by default because it was too imprecise, but it has been rewritten to eliminate nearly all false positives.)
unusedparam1 unusedparam2 unusedparam3

Automated crash reporting (off by default)

The v1.23 release of Go expected in August contains a feature that makes it possible for a Go program to monitor itself for unexpected crashes of any kind. When gopls is built with the latest Go toolchain, it will enable this feature and save crash reports into the local telemetry database.

If you have elected to enable data collection by running this command:

$ go run golang.org/x/telemetry/cmd/gotelemetry@latest on

then these crash reports will be uploaded to https://telemetry.go.dev, helping us identify crashes and quickly fix them.

We respect your privacy. The crash reports contain only stack traces, that is, lists of names of functions from the gopls source code. They do not contain any values derived from your source code or environment.

The v0.14 release of gopls reported limited telemetry data about a handful of sites in the code where we had added explicit assertions. We are grateful to users who enabled telemetry as even this limited data proved tremendously valuable and led to numerous bug fixes.

Housekeeping

Finishing up the redesign work from v0.12, we've made a number of clarifications to the internal structure of the project, including rationalizing the directory layout, breaking dependencies, minimizing and documenting our internal APIs, and converging our tests on a standard form. We believe it is now easier than ever before to contribute features to gopls, and have been heartened by an uptick in contributions from the broader community, including:

Bug fixes

In addition to the new features listed above, this release includes numerous minor ones, including:

  • The "add missing imports" feature (typically invoked on save) is much less likely to block, a commonly reported source of freezing following a save (golang/go#59216).
  • Hovering over a type now displays the set of accessible fields and methods, even though embedded fields (golang/go#61634).
  • gopls supports "workspace vendoring" (golang/go#63375).
  • Completion now substitutes type arguments in generic snippets when they are known (golang/go#61189).
  • Completion now omits type parameters when they can be inferred from the arguments (golang/go#51783).

A major theme for this release is stability: we have fixed a large number of crash bugs.

A full list of all issues fixed can be found in the gopls/v0.15.0 milestone.
To report a new problem, please file a new issue at https://go.dev/issues/new.

End of support for Go 1.18

This is the last release of gopls that may be built and used with Go 1.18. If built or used with Go 1.18, it will display a message advising the user to upgrade. See supported Go versions for details.

Don't miss a new tools release

NewReleases is sending notifications on new releases.