[英]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.