首先你要正确地安装了插件。

环境

Windows 10, GO 1.15

GOROOT=c:\go

GOPATH=E:\OneDrive\code\go

问题描述

如果我们设置GO111MODULE环境变量,其值为on时自动补全很慢,其值为off时补全正常。

ebbe9b5c2631

image.png

(说明:必须要按照在图片里那样设置环境变量,不要运行命令行set; 每次改变变量需要重启VSCode)

gomod肯定不能关了,怎么解决呢?

解决方法

go的自动补全靠的时gocode,我们可以gocode -debug查看偏移,自动补全正常时偏移小于1ms,设置为on时偏移有3秒

很自然地我们去GitHub看看项目

gocode

人家直接写着:

You should have a correctly installed Go compiler environment and

your personal workspace ($GOPATH). If you have no idea

what $GOPATH is, take a look here

(http://golang.org/doc/code.html). Please make sure that

your $GOPATH/bin is available in your $PATH. This is

important, because most editors assume that gocode binary is

available in one of the directories, specified by

your $PATH environment variable. Otherwise manually copy

the gocode binary from $GOPATH/bin to a location which is

part of your $PATH after getting it in step 2.

我就试了下, 但是我的操作有失误但歪打正着:

我把

copy the gocode binary from $GOPATH/bin to a location which is

part of your $PATH

看成

copy the gocode binary from $GOPATH/bin to a location which is

part of your $GOPATH

就是把$GOPATH/bin中的gocode.exe复制到了$GOPATH中

ebbe9b5c2631

image.png

ebbe9b5c2631

image.png

这不就大功告成了嘛😘😘😘😘