簡體   English   中英

Golang VSCode 配置最佳設置

[英]Golang VSCode configuration best setup

我想知道是否有人可以在 Mac 上使用 Vscode 分享他們對 Golang 的最佳設置。 由於我不斷遇到問題,例如:

  1. 有時 gomft 不起作用。
  2. 在同一包中定義的函數顯示有紅色下划線警告,表示未定義(但在運行時有效)
  3. 彈出以下消息

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
        },
    },

go.useLanguageServer: false,可能對你有幫助

我看到了同樣的問題,並且還使用golangci-lint作為 lint 工具。 當我查看 Go 擴展的輸出時(視圖 > 命令托盤 > 輸出:專注於輸出視圖;然后在輸出視圖的下拉列表中選擇“Go”),我看到如下錯誤:

Error while running tool: /usr/local/bin/golangci-lint run --print-issued-lines=false
level=warning msg="[runner] Can't run linter goanalysis_metalinter: assign: failed prerequisites: inspect@example.com/pkg/example"

和這個

level=error msg="Running error: buildssa: analysis skipped: errors in package: [/Users/tschaub/projects/pkg/example.go:6:15: undeclared name: SomethingIJustStartedTyping

第一個錯誤( assign: failed prerequisites )在https://github.com/golangci/golangci-lint/issues/827 中被罰單,並以關於更新到golangci-lint@v1.24.0的評論golangci-lint@v1.24.0

第二個錯誤 ( buildssa: analysis skipped ) 在https://github.com/golangci/golangci-lint/issues/896 中被罰單,並在我輸入時收到新評論。

升級到 v1.24.0可能無法解決問題,但聽起來它可能會生成更具描述性的輸出。

即使使用golangci-lint@v1.24.0也不能解決我的問題。 每當我進入這種“錯誤配置”狀態時,我都需要退出 VSCode 並重新啟動它。 我希望在工具趕上 go 模塊之后,事情會更加穩定/可靠。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM