[英]Why does the vscode golang plugin remove spaces around operators on save?
[英]Why does vscode delete golang source on save
为什么不能在带有 golang 扩展的 vscode 中保存这些代码行
package app
import (
"fmt"
)
//this is just func
func TestingHello(){
fmt.Println("Hissssss")
}
只有package app
保留,其余部分在 vscode 中保存时被删除。
基本上,您的 formatOnSave 正在运行,这导致了这个问题。
要禁用它,请转到您的命令面板 (Ctrl+Shift+P),输入“配置语言特定设置”,然后查找 Go。
您现在应该会看到一个 json 文件,您可以在其中添加以下设置:
"editor.formatOnSave": false.
这是 json 文件的样子,如果你只是修改了 go 的设置:
{
"window.zoomLevel": 1,
"[go]": {
"editor.formatOnSave": false,
}
}
在 settings.json 中配置 editor.formatOnSave 和 editor.codeActionsOnSave :
"[go]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.organizeImports": false
},
},
"go.formatTool": "gofmt",
默认情况下,格式工具在 settings.json 中设置为“goreturns”,将其更改为“fmt”:
{
"go.formatTool": "gofmt"
}
现在您可以评论导入:
import (
"fmt"
// "reflect"
// "math/rand"
)
我有一个类似的问题,是由于方法名称的大小写不正确造成的。
在以下代码中, import "fmt"
将消失。
package main
import "fmt"
func main() {
fmt.println("hello world")
}
解决方案我应该调用Println
NOT println
! 注意大写的P
。 一旦更改goreturns
添加导入而不是删除它。
这似乎很奇怪。
我可以理解由于goreturns
( github.com/sqs/goreturns
)删除了未使用的导入,导入消失了(如issue 748 )。 但这不应该适用于您的情况。
但是如果几乎所有东西都消失了,那就意味着文件无法保存,并恢复到其原始内容。
也许另一个进程正在保留该文件的句柄,从而阻止保存操作继续进行。
Ctrl+Shift+P --> 配置语言特定设置
"editor.insertSpaces": false,
"editor.formatOnSave": **false,**
"editor.codeActionsOnSave": {
"source.organizeImports": **false**
}
}
}
之所以出现这种情况,是因为你导入了什么,你没有在程序中使用它,所以Golang删除了不必要的依赖。
在 VScode 上只需按 (CTRL + SHIFT + P )。
然后,单击“配置特定于语言的设置”并选择 GO lang。
贴代码就好
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.