New Features
Gopls now integrates with staticcheck@v0.3.0, which supports
generics. To enable staticcheck analyzers, set "staticcheck": true
in your gopls settings. Note that as part of this change, staticcheck
is only supported when gopls is built with Go 1.17+.
New Features
Fuzz target inference: Gopls will now infer the type of Fuzz targets from
preceding testing.F.Add statements.
Generic completion improvements: This release includes several improvements to
auto-completion of generic code. For example, completion of type or function
instantiation now prefers types that are in terms of the constraint type set.
Bugfixes
The timing of this release is primarily driven by golang/vscode-go#2121, a
panic when go.work files are missing a go directive. We received enough reports
of this crash to know that it was affecting a significant number of users.
Thanks to all those who reported issues - your diligence helps us make gopls
better!
Go version support
Support for Go 1.18
Version 0.8.0 of gopls supports features added to Go 1.18,
specifically:
Support for multi-module workspaces using go.work files.
Diagnostics for Fuzz tests. Improved support for generics.
To use these features, gopls must be installed using Go 1.18. See
go.dev/dl for the latest status of Go 1.18 -- as of writing Go 1.18
is not yet released, but Go 1.18 RC1 may be used.
Dropped support for Go 1.12
Version 0.8.0 of gopls no longer supports building at Go 1.12. See
golang/go#50827 for more details.
New Features
go.work integration
Gopls now supports multi-module workspaces using go.work files. To
use this feature, create a go.work file that includes the modules
you want to work on, and then open your editor to the directory
containing go.work. For more information, see the go.work reference,
or the gopls documentation for multi-module workspaces.
Diagnostics for Fuzz tests
When writing Fuzz tests, gopls provides diagnostics for invalid
arguments to Fuzz.
Improved support for generics
Honor the language version configured in go.mod
gopls now provides diagnostics for language features based on the
go directive in the applicable go.mod file for a package.
For some errors related to incompatible language versions, gopls
offers a quick-fix to update the go.mod Go version. (note that if
the go.mod file is open, it may need to be saved in order for
language version changes to take effect)
gomodedit
Improved completion with type parameters
Gopls autocompletion is improved in several contexts when using
generic types.
genericvarcompl
New code action to add missing method stubs
Gopls now provides a code action to implement missing methods.
Improved performance and accuracy for workspace symbol requests
Workspace symbols uses a new fuzzy matcher that is up to 3x faster
than previous, and has improved ranking. See golang/go#50016 for
more details. Note that the first time workspace symbols are
requested, there may be a delay as the symbol cache is populated.
Improved gofumpt integration
Gopls now sets the language version and module path when invoking
gofumpt, allowing more accurate formatting based on context.
Configuration changes
templateExtensions now defaults to []
Following feedback on the template features introduced with v0.7.4,
we have made improvements to the way the active set of template
files is configured. The templateExtensions setting is now empty
by default, and gopls recognizes any open files with the "gotmpl"
language identifier as a template file. As a result, unopened files
will not be loaded as Go templates unless the templateExtensions
is configured to be non-empty, but gopls will still provide template
language features to any open files configured to be Go template
files by the LSP client.
As always, your feedback helps make gopls better, and is greatly
appreciated!
Features
New postfix completions
The split! completion on values of string type inserts a
strings.Split snippet. split
The join! completion on values of []string type inserts a
strings.Join snippet. join
New suggested fix for unused function parameters
The diagnostic for unused function parameters now includes a
suggested fix to rename the parameter to _. This diagnostic is
disabled by default, but can be enabled via the unusedparams setting
in the analyses section.
Features
Editing support for Go template files
Gopls support for template files is now generally available. While
editing files intended for use with the text/template or html/template
packages, gopls can provide completion, syntax highlighting,
jump-to-definition, find references, and diagnostics.
To use this feature, your editor or LSP client must be configured
to activate gopls for Go template files. By default, gopls considers
files ending with .tmpl or .gotmpl to be template files, though
this is configurable via the templateExtensions setting. More
information in the documentation.
Improved support for generic code when using the Go 1.18 beta
This release includes several bug fixes related to editing generic
code, as well as many improvements to diagnostic precision when
operating on type parameters. See the documentation for instructions
on how to build gopls using a version of Go that supports generic
code.
Exclude node_modules from the workspace by default
The directoryFilters setting now defaults to [-node_modules], since
these directories never include Go code. This only applies to
node_modules directories at the top level of the workspace, not
arbitrary depths.
Detailed hover for runes
You will now see more information about the rune when you hover
over it. For example:
Undeclared name suggested fix for functions
The undeclaredname analyzer now offers a suggested fix for undeclared
function. Depending on the surrounding code, the suggested fix will
either insert a new variable declaration (as before), or a new
function declaration with inferred parameters and a body that
panics. For example:
New analyzers for generic code (only with Go 1.18)
useany: Check for constraints that could be simplified to "any"
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
All checksums have been double-checked against existing RMD160 and
SHA512 hashes
Could not be committed due to merge conflict:
devel/py-traitlets/distinfo
The following distfiles were unfetchable (note: some may be only fetched
conditionally):
./devel/pvs/distinfo pvs-3.2-solaris.tgz
./devel/eclipse/distinfo eclipse-sourceBuild-srcIncluded-3.0.1.zip
Features
Experimental
Support go.work files (proposal)
In order to better support the new proposal for a multi-module
workspace mode (golang/go#45713), gopls has added support for
go.work files. Try adding a go.work file to the root of your module
(you still need to enable experimentalWorkspaceModule mode) and
try out the proposal!
Use invalid metadata
Set experimentalUseInvalidMetadata to true in your settings, and
gopls will reuse outdated metadata until new package metadata has
been successfully reloaded. This is useful if your go.mod file is
temporarily invalid. In a future release, this setting will be
moved out of experimental and deleted.
Features
Postfix completions
Postfix completions are a new style of completions that can save
you time by inserting more complex pieces of commonly-written code.
All of the results end with !. This feature was added experimentally
in gopls/v0.6.10 and is now enabled by default.
New commands: List known packages and add import
These commands can be used to manually list available packages to
import and then add an import to your file. They are currently not
used by any known clients, but they will be made available through
the Command Palette in VS Code in the next VS Code Go release.
Improvements
Memory usage
Improved trimming of the ASTs of dependency packages results in
reduced memory usage, especially for projects with many dependencies.
This may result in some hard-to-diagnose bugs that we're not yet
aware of, so please report any surprising behavior via
https://golang.org/issues/new.
Features
t.Fatal snippet
If you trigger completion in a test function, on the line after a
call to a function that returns an error, you will be offered a
completion snippet for:
if err != nil {
t.Fatal(err) }
Experimental
Postfix completion snippets
Postfix completions are a new style of completions that can save
you time by inserting more complex pieces of commonly-written code.
All of the results end with !. Enable this feature by setting
"ui.completion.experimentalPostfixCompletions": true.
0.6.9
This is a patch release to fixgolang/go#45092.
0.6.8
This is a patch release to fixgolang/go#45075.
0.6.7
New analyzers
The unusedwrite and nilness analyzers are now available, but they
are disabled by default. Note that enabling them permanently may
significantly increase memory usage. You can configure analyzers
through the analyses setting. Improved hover with time.Duration
Hover for any constant of type time.Duration is shown both in
nanoseconds and as a human-readable string.
Fixes
A full list of all issues fixed can be found in the gopls/v0.6.7
milestone. To report a new problem, please file a new issue at
https://golang.org/issues/new.
Show available upgrades for dependencies
gopls/v0.6.0 removed support for the code lenses that showed
available upgrades for dependencies. This behavior has now been
reintroduced, with an improved UI. Users must explicitly request
this information by clicking the "Check for upgrades" code lens
above the go.mod file's require block. Any module with available
upgrades will be highlighted with an informational diagnostic and
accepting its suggested fix will preform the upgrade.
gopls/v0.6.4
Includes fixes for https://blog.golang.org/path-security.
gopls/v0.6.3
This release has a number of bug fixes and documentation improvements.
Features
Shadow analyzer
This off-by-default analyzer flags shadowed variables. Learn more
in the Analyzers documentation.
Experimental
New keys for the GC details "annotations" setting
The previous keys were prefixed with "no" and meant to disable
certain GC details checks, which was inconsistent with the style
of our other settings maps. A warning will appear suggesting a
change to the new key name, but the old settings will continue to
work. Full details can be found in the annotations documentation.
Documentation
Improved documentation for available analyzers.
Improved documentation for Vim.
Fixes
Editing the go.mod file by hand (golang/go#42529)
This issue was previously marked as resolved, but it had not actually
been fixed. Package metadata will now only be invalidated when a
go.mod file is saved, so you will need to save before expecting
your changes to be propagated. This should significantly reduce
the number of go list calls (and therefore CPU utilization) as you
edit the go.mod file.
0.6.1
This is a patch release to fixgolang/go#43234. The titles of some
suggested fixes were blank, leading to a bad user experience.
0.6.0
Features
- Default to -mod=readonly
- Default to GOPROXY=off
- Inclusion/exclusion filters for directories
- Debouncing for diagnostics
- "Upgrade direct dependencies" code lens
- Support for filling a partially-populated struct
- Experimental: Field alignment analyzer
Fixes
- Improvements to diagnostics tracking
- File watching for directories
Other
- "codelens" setting name changed to "codelenses"
- Disabled support for symlinks
0.5.5
This is a patch release to fix two bugs in gopls/v0.5.4.
Fixes
Excessive reloading of packages outside of GOPATH or a module
File corruption with CRLF line endings and //-style comments
golang/go#42646 was supposed to have been fixed in gopls/v0.5.4,
but it was not. golang/go#42923 was reported and fixed.
0.5.4
Features
Opening a project that contains a module in a subdirectory
Previously, gopls required that you open your editor exactly at or
below the module root (the directory containing the go.mod). Now,
you can open a directory that contains exactly one module in a
subdirectory, and gopls will work as expected. For details on
multi-module workspaces, see below.
Removal of the granular go.mod upgrade codelenses
Previously, we offered a code lens to suggest upgrades for each
require in a go.mod file. In anticipation of changes that limit
the amount that gopls accesses the network, we have decided to
remove and reevaluate this feature. Users had mentioned that the
code lenses cluttered their go.mod files, especially if they didn't
actually want to upgrade. golang/go#38339 tracks the work to revamp
this feature. An "Upgrade all dependencies" code lens should still
appear at the top of your go.mod file.
Improved error message reports
Previously, critical error messages were reported as message pop-up
that would re-trigger as you type. Many users would find this
annoying. We have changed the approach to show error messages as
progress reports, which should be less intrusive and appear more
like status bars.
Improved memory usage for workspaces with multiple folders
We are now using a coarser cache key for package type information.
If you use the gopls daemon, this may reduce your total memory
usage.
Experimental
Multi-module workspace support
The proposal described in golang/go#32394 is still in development
and off by default. See our progress by tracking the multi-module
workspace milestone and project.
Enable multi-module workspace support by adding the following to
your settings:
"gopls": { "experimentalWorkspaceModule": true, }
With this setting, you will be able to open a directory that contains
multiple modules or a directory that contains nested modules.
Give this a try if you're interested in this new feature, but please
note that it is still very experimental. Please file issues if you
encounter bugs.
Fixes
File corruption with CRLF line endings and /**/-style comments
Previously, when you organized the imports in a file with CRLF line
endings and multi-line comments, the formatter might output incorrect
content for the file, rendering it invalid Go code. This issue has
popped up a number of times, but we believe it has finally been
fixed for good. If you are using Windows with CRLF line ending,
please report any regressions. For full details, see golang/go#42646.
Features
Automatic updates to go.sum
Previously, go.mod-related quick fixes would not make corresponding
changes to your go.sum file. Now, when you add or remove dependencies
from your module, your go.sum will be updated accordingly.
Removed support for go mod tidy on save
We have removed the support for running go mod tidy on save for
go.mod files. It proved to be too slow and expensive to be worth
it.
Experimental
Multi-module workspace support
The proposal described in golang/go#32394 is still in development
and off by default. See our progress by tracking the multi-module
workspace milestone and project.
Enable multi-module workspace support by adding the following to
your settings:
"gopls": { "experimentalWorkspaceModule": true, }
With this setting, you will be able to open a directory that contains
multiple modules. Most features will work across modules, but some,
such as goimports, will not work as expected.
Give this a try if you're interested in this new feature, but please
note that it is still very experimental.
Fixes
A list of all issues fixed can be found in the gopls/v0.5.3 milestone.
Features
No new features have been added in this release.
Experimental
We have added support for a new allExperiments setting. By enabling
this flag, you will enable all experimental features that we intend
to roll out slowly. You can still disable individual settings (full
list of settings). In-progress features, such as multi-module
workspaces (below), will remain disabled until they are ready for
users.
Improved CPU utilization: experimentalDiagnosticsDelay
experimentalDiagnosticsDelay controls the amount of time that gopls
waits after the most recent file modification before computing deep
diagnostics. Simple diagnostics (parsing and type-checking) are
always run immediately on recently modified packages.
Enable it by setting it to a duration string, for example "200ms".
With allExperiments, this is set to "200ms".
Improved memory usage for workspaces with multiple folders:
experimentalPackageCacheKey
experimentalPackageCacheKey controls whether to use a coarser cache
key for package type information. If you use the gopls daemon, this
may reduce your total memory usage.
Enable it by setting it to true. With allExperiments, this is set
to true.
Multi-module workspace support
The proposal described in golang/go#32394 is still in development
and off by default. See our progress by tracking the multi-module
workspace milestone and project.
Enable multi-module workspace support by adding the following to
your settings:
"gopls": { "experimentalWorkspaceModule": true, }
With this setting, you will be able to open a directory that contains
multiple modules. Most features will work across modules, but some,
such as goimports, will not work as expected.
Give this a try if you're interested in this new feature, but please
note that it is still very experimental.
Support for semantic tokens
This is a new, unreleased LSP feature that provides additional
syntax highlighting. In advance of this new LSP version, we have
added preliminary support for this feature. Enable it by setting:
"gopls": { "semanticTokens": true, }
It will not be enabled with allExperiments.
Fixes
A list of all issues fixed can be found in the gopls/v0.5.2 milestone.
For editor clients
All command names have been given gopls. prefixes, to avoid
conflicting with commands registered by other language servers.
This should not have affected any clients.
Features
Completion speed improvements
https://golang.org/cl/257240 eliminated some duplicate type-checking in completions (and some other features), halving latency in most cases.
Improvements to symbol rankings
From https://golang.org/cl/254037:
Downrank symbols if they are:
Unexported and outside of the workspace. Since one wouldn't jump to these symbols to e.g. view documentation, they are less relevant.
Fields and interface methods. Usually one would jump to the type name, so having fields highly ranked can be noisy.
Warnings for excluded files
You will now see diagnostics if you open a file that is excluded from the current build, likely by build tags. This should aid in understanding cases when gopls fails to work on a certain file.
Better error reporting when code lenses fail
A pop-up with an error will appear if a code lens fails to run its command.
Experimental
Multi-module workspace support
The proposal described in golang/go#32394 is partially implemented, but off by default.
Enable multi-module workspace support by adding the following to your settings:
"gopls": {
"experimentalWorkspaceModule": true,
}
With this setting, you will be able to open a directory that contains multiple modules. Most features will work across modules, but some, such as go mod tidy diagnostics, are not yet implemented.
Give this a try if you're interested in this new feature, but please note that it is still very experimental.
Fixes
Toggle GC Details on Windows
There was a bug in the new experimental GC details code lens on Windows machines (golang/go#41614). We added a work-around to fix the issue.
A list of all issues fixed can be found in the gopls/v0.5.1 milestone.
Documentation
The documentation for settings is now automatically generated so it will stay up-to-date. Documentation was also updated for working with Neovim and for working on the Go project itself.
Thank you to our contributors!
@heschik @findleyr @dandua98 @pjweinb @ainar-g
Memory usage
- Rewrite of caching model, resulting in significant memory usage improvements
(@heschik).
New features
- Extract to function: Support for extracting code blocks that contain return
statements (@joshbaum).
- Workspace symbols: Support for fzf-style search syntax (@findleyr). The
following syntax is supported:
' for exact matching
^ for prefix matching
$ for suffix matching
Note: This feature does not yet work in VS Code. See golang/vscode-go#647 and
microsoft/vscode#106788.
- An experimental new code lens to view GC optimization details (@pjweinb).
Once the code lens is enabled, you will see a Toggle gc details annotation at
the top of your file. Clicking it will show optimization diagnostics produced
by the Go compiler, and clicking it once again will hide these diagnostics.
Enable the code lens by adding the following to your settings:
"codelens": {
"gc_details": true
}
- go mod tidy and go mod vendor code lenses for go.mod files (@dandua98).
- Support for filling in matching in-scope variables instead of just empty
values in fillstruct and fillreturns (@joshbaum).
- Autocompletion within import statements (@dandua98).
- Autocompletion within package declarations (@dandua98).
Improvements
- Improvements to workspace symbols ranking and fuzzy matching (@findleyr,
@myitcv).
- Better completion suggestions in type switch case clauses and for calls to
append, function literals, and unnamed types (@muirdm).
* Support for opening a single file. Previously, gopls required
you to open an entire directory.
* Support features and diagnostics for the entire module, even when
you open a subdirectory of the module.
* Extract a selected range to a variable or to a function. This
feature is still relatively new, so please report issues if you
encounter any. (@joshbaum)
* Fillstruct performance improvements. It is now enabled by default
again. (@joshbaum)
* Improvements in go.mod diagnostic error presentation.
0.4.3
Disable the fillstruct analysis by default.
We recently uncovered some performance issues with the analysis, leading us to disable it by default.
Once those issues are resolved, we will enable it by default again.
You can still enable it by adding the following to your VS Code settings:
"gopls": {
"analyses": {
"fillstruct": true,
}
}
gopls/v0.4.2
Significant memory improvements (@heschik). Dependency test variants and vendored packages are no longer considered "workspace packages".
Smart autocompletion for "append" (@muirdm).
A "fill struct" code action to suggest populating a struct literal with default values (@luciolas, @joshbaum).
Better cgo support with Go 1.15 (@heschik). Learn more: golang/go#35721 (comment).
Code lens to run Go tests directly in the editor (@martskins). Currently opt-in:
"gopls": {
"codelens": {
"test": true,
}
}
Improved folding in composite literals (@joshbaum).
Pop-up suggestion to run go mod vendor when inconsistent vendoring detected (@stamblerre).
Respect GOPRIVATE for all document links and links on hover (@findleyr).
A full list of issues resolved in this release can be found in the gopls/v0.4.2 milestone.
gopls/dev.go2go: You can use the new go2go prototype with gopls. See golang/go#39619.