Problem with formatting go code in vscode editor

1.9k views Asked by At

In a fresh VSCode 1.52.1, I have installed Go extention by Go Team at Google v0.19.1 as well as the suggested go packages but the auto format at save does not work as it should.

go version go1.14.6 linux/amd64

In settings.json I have

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

I used to have a nice autoformat (goftm) effect before on another vscode editor, but I don't have access to that machine and I don't remember what where the exact extensions there. so I'm not sure what is missing here,and appreciate your hints.

1

There are 1 answers

0
Daniel Cruz On

Adding this to settings.json fixed it for me:

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