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.
In the Go Developer Survey 2020 Results, 41% of respondents chose Visual Studio Code as their most preferred editor for Go. This makes Visual Studio Code the most popular editor for Go developers. Visual Studio Code and the Go extension provide IntelliSense, code navigation, and advanced debugging.
By default, VS Code requires an explicit action to save your changes to disk, Ctrl+S. However, it's easy to turn on Auto Save , which will save your changes after a configured delay or when focus leaves the editor. With this option turned on, there is no need to explicitly save the file.
You can invoke the vscode window property to retrieve the file path or name depending on what you are looking for. This will give you the name of the file open in the current Tab when you execute the command.
Basically, your formatOnSave is on for go which is causing this problem.
To disable it, go to your Command Palette (Ctrl+Shift+P), 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 it:
"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, } }
config both editor.formatOnSave and editor.codeActionsOnSave in the settings.json:
"[go]": { "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.organizeImports": false }, }, "go.formatTool": "gofmt",
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