How to make Visual Studio Code (or Go Programming Language Extension) to run go fmt
(or other tools/commands) on save? Even auto save?
Update: It is working now perfectly inside VSCode, at this time; just need to add some config files inside .vscode directory (I use these).
Update 2019: This question is old. The VSCode Go extension has all you need to develop in Go, now.
Last Update 2019 BTW It worth mentioning that right above the package declaration inside your test files appears a run package tests. If you click it, you can see your code coverage of your code. The covered and not-covered parts are highlighted in different colors.
Update 2020 And now, the Go Extension for VSCode, is under the supervision of Go Team! 🎉
If you don't already know how to, you can get there by going to File > Preferences > Settings or hitting Ctrl + ,(Cmd + , if you're on a Mac). Then click the Extensions tab on the left side menu, look for the extension Run On Save, and click Edit in settings. json. Run On Save settings page.
If your version of GoLand 2021.2 or higher, you can enable Run gofmt on code reformat option under Preferences/Settings | Editor | Code Style | Go | Other (it is enabled by default). After that, execute Code | Reformat Code ( Option + Command + L on macOS) and gofmt will be executed after internal GoLand formatter.
Now, the feature has been implemented, you can enable format on save:
Ctrl + ,
)editor.formatOnSave
and set it to true
Your Go code will be formatted automatically on Ctrl + s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With