This extension mostly supports Go modules. However, certain features have not been ported to work with modules. The reason for this is that the Go team is developing a language server, gopls
. This provides a comprehensive solution for Go modules support in all editors.
However, as described in the language server documentation, gopls
is still in an alpha state, so it is not yet the default in VS Code Go. We understand that many users will not want to use alpha software, so this document describes how this extension works with Go modules, without the language server.
To learn how to use the language server with modules in VS Code, read our gopls
documentation.
As mentioned above, not all Go tools have been ported to work with modules. Many tools will never be ported, as they are being replaced by gopls
. golang/go#24661 contains up-to-date information about modules support in various Go tools.
The default formatting tool, goreturns
, has not been ported to work with modules. As a result, you will need to change your "go.formatTool"
setting for formatting and import organization support. We recommend changing the value to "goimports"
instead. Other options are also available, and you can read about them in the format tools documentation.
The tools that provide these two features, guru
and gorename
, have not been updated for Go modules. Instead, they will be replaced by gopls
.
Go modules introduced additional complexity to Go tooling. As a result, the performance of a number of tools is worse with modules enabled. Hopefully, you will not notice this too frequently.
One case in which you may notice this is autocompletion. The best solution to this is to switch to gopls
, which makes use of an in-memory cache to provide results quickly.