'VScode format as save not work for Golang
I'm using vscode and developing a go project via remote-ssh. However, the format on save does not work. I found it works on the normal project without git. If I remove the .git, it will work as expected. Does anyone have some advice for me?
The version of the environment is as follows:
- vscode 1.63.2
- go 1.17.6
- remote machine Ubuntu 20.04
- go extension v0.30.0
Solution 1:[1]
Try to format your code manually by pressing Ctrl + Shift + P to open Command Palette and select Format Document. If your file is being properly formatted without any issues, it means there is something wrong in formatOnSave settings.
Choose a default formatter instead of null. like this :
"editor.defaultFormatter": "esbenp.prettier-vscode"
Uninstall other formatters one by one to see if anything causes the conflict.
Try to make it Language specific.
For better understanding refer this link : https://github.com/microsoft/vscode/issues/108447
About Git Specific:
It may be the case that you are running Git Atom. Atom is a desktop application, so may be causing problems in accessing the remote installation path.Try installing Git Repo.
Also make sure Go: Install/Update Tools are up-to-date.
Solution 2:[2]
I had the same issue recently, auto format would only work on projects without a .git directory. What solved the issue for me was to change Format On Save Mode from modificationsIfAvailable to file. Since I prefer modificationsIfAvailable over file for everything, I changed to have formatOnSaveMode to file only for go source files with:
"[go]": {
"editor.formatOnSaveMode": "file"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gopher88 |
| Solution 2 | Thiago Pontes |
