Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang VSCode configuration best setup

I wonder if someone can share their best setup for Golang using Vscode on Mac. As I am continously having issues such as:

  1. sometimes gomft doesn't work.
  2. Functions defined in the same package shows with a red underline warning saying it's not defined (but works when running it)
  3. having the following message popped up

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.

Here are some information of my go setup:

  • Version: go1.13.4 darwin/amd64
  • Settings in '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 is pointing to the folder where Go is installed
like image 960
blackmamba24 Avatar asked Jan 25 '23 06:01

blackmamba24


1 Answers

you can try this setting.

    "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
        },
    },
like image 123
youngsailor Avatar answered Jan 29 '23 10:01

youngsailor