【问题标题】:Problem with formatting go code in vscode editor在 vscode 编辑器中格式化 go 代码的问题
【发布时间】:2020-12-22 09:47:11
【问题描述】:

在新的 VSCode 1.52.1 中,我已经安装了 Go Team at Google v0.19.1 的 Go 扩展以及建议的 go 包,但保存时的自动格式无法正常工作。

go version go1.14.6 linux/amd64

在 settings.json 我有

{
    "go.addTags": {
        "template": "tmpl"
    },
    "go.autocompleteUnimportedPackages": true,
    "editor.formatOnSave": true,
    "go.formatTool": "gofmt",
    "emmet.preferences": {
    
    },
    "go.useLanguageServer": true,
    "go.overwriteGoplsMiddleware": {
    
    }
}

我以前在另一个 vscode 编辑器上曾经有一个很好的自动格式化 (goftm) 效果,但我无法访问那台机器,我不记得那里的确切扩展名在哪里。所以我不确定这里缺少什么,感谢您的提示。

【问题讨论】:

  • 我删除了那个,但问题仍然存在。

标签: go visual-studio-code gofmt


【解决方案1】:

将此添加到settings.json 为我修复了它:

  "[go]": {
      "editor.defaultFormatter": "golang.go"
    },

【讨论】:

    猜你喜欢
    • 2022-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 2017-09-09
    相关资源
    最近更新 更多