最重要的是检查两个东西是否安装:1、VSCode的Go扩展,2、检查几个相关的package是否安装(gocode, gopkgs, godef, go-outline)。
在windows环境下用Anaconda创建了golang环境测试了一下,用VSCode打开.go文件,是有IntelliSense的:
步骤如下。
conda create -n golang go
conda activate golang
go get -u github.com/gin-gonic/gin
然后启动VSCode,安装Go插件:
之后打开你的.go文件,会提示安装以下模块,点击install按钮:
或者在golang环境用命令行安装:
go get -v github.com/mdempsky/gocode
go get -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
go get -v github.com/rogpeppe/godef
go get -u github.com/ramya-rao-a/go-outline
go get -v github.com/sqs/goreturns
补全都比较正常:
相关package版本如下:
(base) C:\projects>conda activate golang
(golang) C:\projects>conda list
# packages in environment at C:\Users\chanc\.conda\envs\golang:
#
# Name Version Build Channel
_go_select 2.3.0 cgo conda-forge
go 1.13.10 h4e67994_3 conda-forge
m2w64-binutils 2.25.1 5
m2w64-bzip2 1.0.6 6
m2w64-crt-git 5.0.0.4636.2595836 2
m2w64-gcc 5.3.0 6
m2w64-gcc-ada 5.3.0 6
m2w64-gcc-fortran 5.3.0 6
m2w64-gcc-libgfortran 5.3.0 6
m2w64-gcc-libs 5.3.0 7
m2w64-gcc-libs-core 5.3.0 7
m2w64-gcc-objc 5.3.0 6
m2w64-gmp 6.1.0 2
m2w64-headers-git 5.0.0.4636.c0ad18a 2
m2w64-isl 0.16.1 2
m2w64-libiconv 1.14 6
m2w64-libmangle-git 5.0.0.4509.2e5a9a2 2
m2w64-libwinpthread-git 5.0.0.4634.697f757 2
m2w64-make 4.1.2351.a80a8b8 2
m2w64-mpc 1.0.3 3
m2w64-mpfr 3.1.4 4
m2w64-pkg-config 0.29.1 2
m2w64-toolchain 5.3.0 7
m2w64-toolchain_win-64 2.4.0 0 conda-forge
m2w64-tools-git 5.0.0.4592.90b8472 2
m2w64-windows-default-manifest 6.4 3
m2w64-winpthreads-git 5.0.0.4634.697f757 2
m2w64-zlib 1.2.8 10
msys2-conda-epoch 20160418 1