准备材料
在 《VSCode 远程 Linux 的 Golang 开发环境搭建(备忘)》 Windows 机(外网)都通顺后
准备以下材料:
其他须知
- go env
- 可以获取 go GOPATH ,比如 /home/fananchong/go ,windows 也一样
材料 | 目录位置 | 说明 |
---|---|---|
extensions | Windows 机 %USERPROFILE%.vscode\extensions | VSCode 插件安装都在这个目录下 |
linux.go.bin | Linux 机 /home/fananchong/go/bin/ | ms-vscode.go 安装好后,提示安装的 go 工具在这个目录下 |
win.go.bin | Windows 机 C:\Users\fananchong\go\bin | ms-vscode.go 安装好后,提示安装的 go 工具在这个目录下 |
.vscode-server.zip | Linux 机 /home/fananchong/ | Remote-SSH 服务器端程序、其他 VScode linux 插件等等 |
go.1.14.linux-amd64.tar.gz | 官网或其他渠道下载 | golang |
go.1.14.windows-amd64.msi | 官网或其他渠道下载 | golang |
Microsoft VS Code.zip | C:\Users\fananchong\AppData\Local\Programs | Windows 机 VSCode 安装目录 |
把以上准备材料,拷贝至内网
内网部署
- 使用 go.1.14.linux-amd64.tar.gz 、 go.1.14.windows-amd64.msi 默认方式在 linux 机 、 windows 机上安装 golang
- extensions linux.go.bin win.go.bin .vscode-server.zip Microsoft VS Code.zip 分别解压放到上面介绍的路径下
需要注意:
- linux.go.bin 解压到 linux 机 /home/fananchong/go/bin/ 目录后,注意 chmod +x
- linux 机配置稍微好些,不然
代码自动补全
之类的会延迟很慢 - 一般会提示 git 版本 1.8.x 太低,内网 linux 机上一般你也无法更新 git 版本,直接点击
永久忽略
以上
自动补全延迟太大
linux 机配置太低,会导致 CPU 忙,可以使用下列配置,禁用些功能,加快速度
"go.useLanguageServer": true,
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
// Optional: Disable snippets, as they conflict with completion ranking.
"editor.snippetSuggestions": "none",
},
"[go.mod]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": 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.gocodeAutoBuild": true
- 关于 gopls 在 vscode 中的使用文档,参见: https://github.com/golang/tools/blob/master/gopls/doc/vscode.md
"go.gocodeAutoBuild": true
可以极大的提高响应时间