VS Code loses Go autocompletion on Linux
On my Linux, just after upgrading Go to version 1.9, I lost autompletion functionality in VS Code.
This tip did not work for me.
So let’s try to debug it.
First, we close the auto-completion server (see github.com/nsf/gocode) :
gocode close killall gocode
Then we relaunch it as a server in debug mode inside a console :
gocode -debug -s
So now, we can see what’s happening.
OK, time to try an auto-completion inside VS Code.
Bingo ! We got some useful log :
2018/03/26 23:27:32 Import path "net/http" was not resolved 2018/03/26 23:27:32 Gocode's build context is: 2018/03/26 23:27:32 GOROOT: /usr/local/go 2018/03/26 23:27:32 GOPATH: /home/barim 2018/03/26 23:27:32 GOOS: linux 2018/03/26 23:27:32 GOARCH: amd64 2018/03/26 23:27:32 BzlProjectRoot: "" 2018/03/26 23:27:32 GBProjectRoot: "" 2018/03/26 23:27:32 lib-path: "" 2018/03/26 23:27:32 Error parsing input file (inner block): 2018/03/26 23:27:32 3:6: expected selector or type assertion, found ';' ...
Weird, my GOROOT isn’t at /usr/local/go but at /usr/lib/go.
It seems like gocode doesn’t care about my env and arbitrary choose to look inside this folder.
Ok, let’s trick him with a symlink :
sudo ln -s /usr/lib/go /usr/local/go
Now it works !