[The original answer is outdated; here is up-to-date information provided by the vscode-go maintainers. The updated answer is now marked as “Recommended” in the Go collective]
The plugin has changed a lot since 2019.
- In 2021, Go Modules became the default which may have changed how the program is built and analyzed.
- The vscode-go plugin uses
goplsas the language server by default. Note that in 2019, there were two different language servers andgoplswas still in experimental mode. golintwas deprecated.
If you still have a similar issue, it’s likely that you are seeing a different problem.
Please check the followings:
- Do you have
go.mod? Otherwise, initialize your working module and restart the language server or reload the window. - Is the
go.modfile in the root directory of your workspace? Seegoplsworkspace setup
guide for complex setup. - Do you use build tags or other build constraints? Then see issue 29202. You may need to configure
"go.buildTags"or"go.buildFlags". - If you expect lint errors from linters like
staticcheck,golangci-lint, …, check"go.lintOnSave"is set to the right scope.
If you notice that restarting the language server (“Go: Restart Language Server” command) fixes your issue, that’s a gopls bug. Please consider to file an issue in github.com/golang/vscode-go following the troubleshooting guide.
Otherwise, please open a new question with details.
—– Original answer ——-
I faced same problem. I found that I got into this problem after enabling “Go language server” which is an experimental feature. I disabled it in VS code settings->Go Configuration and after that the problem went away.