Golang VSCode 配置最佳设置

标签 go visual-studio-code installation

我想知道是否有人可以在 Mac 上使用 Vscode 分享他们对 Golang 的最佳设置。由于我不断遇到问题,例如:

  • 有时 gomft 不起作用。
  • 在同一个包中定义的函数用红色下划线警告表示它没有定义(但在运行时有效)
  • 弹出以下消息
  • Your workspace is misconfigured: command-line-arguments has no metadata. Please see https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md for more information or file an issue (https://github.com/golang/go/issues/new) if you believe this is a mistake.
    以下是我的 go 设置的一些信息:
  • 版本:go1.13.4 darwin/amd64
  • “settings.json”中的设置:
  • 
        {
            "window.zoomLevel": 1,
            "workbench.iconTheme": "material-icon-theme",
            "editor.accessibilitySupport": "off",
            "go.useLanguageServer": true,
            "go.formatTool": "gofmt",
            "go.lintTool": "golangci-lint",
            "[go]": {
                "editor.formatOnSave": true,
                "editor.codeActionsOnSave": {
                    "source.organizeImports": true
                },
            },
            "explorer.confirmDragAndDrop": false,
            "javascript.updateImportsOnFileMove.enabled": "always",
            "diffEditor.ignoreTrimWhitespace": false
        }
    
    
  • GOPATH 指向安装 Go 的文件夹
  • 最佳答案

    你可以试试这个设置。

        "go.inferGopath": false,
        "go.buildOnSave": "workspace",
        "go.lintOnSave": "package",
        "go.vetOnSave": "package",
        "go.buildTags": "",
        "go.buildFlags": [],
        "go.lintFlags": [],
        "go.vetFlags": [],
        "go.coverOnSave": false,
        "go.useCodeSnippetsOnFunctionSuggest": false,
        "go.formatTool": "goreturns",
        "go.gocodeAutoBuild": false,
        "go.useLanguageServer": true,
        "go.alternateTools": {
          "go-langserver": "gopls", 
        },
        "go.languageServerExperimentalFeatures": {
          "format": true,
          "autoComplete": true
        },
        "[go]": {
            "editor.codeActionsOnSave": {
                "source.organizeImports": true
            },
        },
    

    关于Golang VSCode 配置最佳设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60497980/

    相关文章:

    go - 时区无法在 Go 1.13 中加载

    .net - 在 .NET 中创建和部署 ActiveX 控件

    go - golang连接池优化

    unit-testing - 需要文件的单元测试方法

    visual-studio-code - VS 代码 : How to sort imports in specific order to go along with InteliJ

    visual-studio-code - 如何下载旧版本的 VSCode 便携版?

    eclipse - 为 eclipse rcp 产品创建 debian 包 (.deb)

    swift - AMScrollingNavbar 不起作用。什么都没发生

    arrays - 为什么我的 2D golang 数组被逐行填充为相同的值?

    python - 有什么方法可以使用 vscode 在绘图查看器中显示交互式绘图吗?