Go intelisense and autocomplete not working in vscode

119 views Asked by At

I have installed go in my mac. In vscode I have installed official go extension. But autocomplete doesn't work.

When I open a go folder I get this in output tab in terminal.

Tools environment: GOPATH=/Users/drexter/go
Installing 1 tool at /Users/drexter/go/bin in module mode.
  [email protected]

Installing golang.org/x/tools/[email protected] (/Users/drexter/go/bin/gopls) SUCCEEDED

All tools successfully installed. You are ready to Go. :)

which go gives '/usr/local/go/bin/go'

I didn't have goroot env variable set. So I set go root export GOROOT=/Users/drexter/go/bin in terminal.

printenv command gives

...
GOPATH=/Users/drexter/go
GOROOT=/Users/drexter/go/bin
...

vscode settings.json -

"go.languageServerFlags": [


  ],
  "go.toolsManagement.autoUpdate": true,
  "editor.tabCompletion": "on",
  "go.installDependenciesWhenBuilding": true,
  "go.formatTool": "gofmt",
  "go.gopath": "~/go",
  "go.useLanguageServer": true,
  "gopls": {
    // Add parameter placeholders when completing a function.
   "usePlaceholders": true,

   // If true, enable additional analyses with staticcheck.
   // Warning: This will significantly increase memory usage.
   "staticcheck": false,
  },
  "go.lintTool": "golangci-lint",
  "go.delveConfig": {
  
  },
  // "go.goroot": "~go/bin",
  "editor.fontSize": 14,
  "[go]": {


    "editor.insertSpaces": false,
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  }

I also uninstalled and installed go extension. tried go nightly extension. None of them working.

Any Idea how to get go autocompletion working.

2

There are 2 answers

0
Shehan DMG On

It worked after reinstalling go

1
Diego Mota On

I run Go in a MacBook Air and I have this config in my .zshrc file:

export GOROOT=/usr/local/go/
export GOPATH=$HOME/go/
export PATH="${GOROOT}/bin:${PATH}"

It works fine for me. But, these variables depends on where you have your Go installed.