1、安装扩展go
2、安装go代码检测所需扩展,command+shift+P 输入 然后键入:go:install/update tools
,将所有 的插件都勾选上,然后点击 OK 即开始安装
如果安装失败,网上说的自行去对应插件地址 比如需要安装 lint 就git clone https://github.com/golang/lint 然后 go build 将编译好的程序放在目录go path上,实在过于麻烦
这里又非常容易安装失败,由于github非常非常缓慢,所以设置一下代理
set GOPROXY=https://goproxy.io;
可以在全局执行或者当前文件夹终端执行
https://goframe.org/prepare/gomodule
以上地址可以获取aliyun或其他的代理地址
等所有都输出
Installing github.com/mdempsky/gocode SUCCEEDED Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED Installing github.com/ramya-rao-a/go-outline SUCCEEDED Installing github.com/acroca/go-symbols SUCCEEDED Installing golang.org/x/tools/cmd/guru SUCCEEDED Installing golang.org/x/tools/cmd/gorename SUCCEEDED Installing github.com/cweill/gotests/... SUCCEEDED Installing github.com/fatih/gomodifytags SUCCEEDED Installing github.com/josharian/impl SUCCEEDED Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED Installing github.com/godoctor/godoctor SUCCEEDED Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED Installing github.com/stamblerre/gocode SUCCEEDED Installing github.com/rogpeppe/godef SUCCEEDED Installing golang.org/x/tools/cmd/goimports SUCCEEDED Installing golang.org/x/lint/golint SUCCEEDED All tools successfully installed. You are ready to Go :).
表示安装扩展依赖完成
3、开启服务,否则不会自动完成或者自动缩进之类
在vscode的设置页面,点击右上角的以json格式配置
新增以下json配置
"go.useLanguageServer": true, "go.goroot": "C:\\Go", "go.formatTool": "goimports",
"[go]": {"editor.formatOnSave": false},
"editor.links": false // 点击引用不打开外部网站
还需要其他配置比如,保存以后不自动格式化等请查阅
https://github.com/Microsoft/vscode-go
或者
https://code.visualstudio.com/
https://github.com/microsoft/vscode-go/wiki/Go-modules-support-in-Visual-Studio-Code
4. 最好将项目放在go默认的个人代码仓库比如
C:\Users\user\go
文件夹下面的src路径