why can't save these line of code in vscode with golang extension
package app
import (
"fmt"
)
//this is just func
func TestingHello(){
fmt.Println("Hissssss")
}
only the package app
stays and remaining part got deleted on save in vscode.
That seems strange.
I can understand the import disappearing (as in issue 748) because of goreturns
(github.com/sqs/goreturns
) removing unused import. But that shouldn't apply in your case.
But if almost everything disappears, that means the file fails to be saved, and revert to its original content.
Maybe another process is keeping an handle on that file, preventing the save operation to proceed.
Basically your formatOnSave is on for go which is causing this problem.
To disable it go to your Command Palette (Ctrl+Shift+P) and type in "configure language specific settings" and look for Go.
You should now see a json file where you can add the following setting to the json file:
"editor.formatOnSave": false.
This is how the json file looks like if you just have on setting modified for go:
{
"window.zoomLevel": 1,
"[go]": {
"editor.formatOnSave": false,
}
}
Hope that helps
By default Format Tool is set to "goreturns" in settings.json, change it to "fmt":
{
"go.formatTool": "gofmt"
}
Now you can comment the imports:
import (
"fmt"
// "reflect"
// "math/rand"
)