Closed Divni closed 5 years ago
goimports
instead of goreturns
If there are errors during formatting, then they will be logged as well.
From the View
menu, select Output
. Select Log (Extension Host)
from the drop down on the top right corner of the panel. This will have logs from the extension host and errors from extensions.
Clear it (there should be a button on the top right corner), try formatting again and see if anything is printed to the logs
I could swear I've been through these steps, but this morning while trying your suggestion I went in and toggled "format on save" on and on and now it appears to be working again. No errors were logged at any time. I'm not sure what went wrong, but it's working again now. Will report back if that changes, but until then it appears my problem is resolved. Thank you!
I have met the same issue and I have configured "editor.formatOnSave
to true.
If I click the "Format Document" on the context menu, the go file can be fotmatted and imports added.
go version
go version go1.12 darwin/amd64
vscode-go configuration
"go.buildTags": "\"reuseport quic kcp zookeeper etcd consul ping rudp utp\"",
"go.buildFlags": [],
"go.lintFlags": [],
"go.vetFlags": [],
"go.coverOnSave": false,
"go.useCodeSnippetsOnFunctionSuggest": false,
"go.autocompleteUnimportedPackages": true,
"go.gotoSymbol.includeGoroot": true,
"go.gotoSymbol.includeImports": true,
"go.gocodeAutoBuild": false,
"editor.formatOnSave": true,
"go.formatTool": "goreturns",
"go.vetOnSave": "package",
The OUTPUT:
It looks the error is caused by formatOnSaveTimeout #2336 , I have set it to 3000 and imported can be added automatically.
Please ignore my comments, thanks.
As of a few weeks ago vscode-go is no longer auto adding imports. My formatter is set to
goreturns
, and when I manually rungoreturns
it works fine. Also it does format my go files, just doesn't add the imports.It seems like there's some sort of environment issue.
To work around this I've installed https://github.com/emeraldwalk/vscode-runonsave, with the following config:
But this is less than idea. I only mention it because I would imagine this command runs with the same environment that vscode-go does its formatting with, and if it doesn't then maybe there's your bug?