实用插件
- One Dark Pro
- Go:可能需要手动安装gopls
- Golang Tools
- Docker
- MySQL(publisher:“Weijan Chen”)
- Material Icon Theme
- YAML
- vscode-proto3
- Makefile Tools
- Thrift
通用配置
- 打开
vscode
时不打开上次项目:在搜索栏中输入 window.restoreWindows
,将其设置为 none
- 设置打开新文件时不关闭原来的文件:在搜索栏中输入
Enable Preview
,取消勾选
- 设置打开新文件夹时不关闭原来的窗口:在搜索栏中输入
Open Folders In New Window
,将其设置为 on
- 自动保存:在搜索栏中输入
Auto Save
,设置为编辑器失焦就保存
go开发环境配置
安装go插件
在扩展商店搜索go
安装,安装后,由于网络原因可能会下载不到gopls
等工具,需要换源后下载依赖工具
- 启用 Go Modules 功能:
1
|
go env -w GO111MODULE=on
|
- 配置 GOPATH(可选),默认在
$HOME/go
,win环境下默认位置会占用c盘空间,直接打开用户环境变量修改
- 配置 GOPROXY 环境变量(以下三选一):
1
2
3
4
5
6
7
8
9
10
11
|
# 七牛 CDN
go env -w GOPROXY=https://goproxy.cn,direct
# 阿里云
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
# 官方
# 旧
go env -w GOPROXY=https://goproxy.io,direct
# 新
go env -w GOPROXY=https://proxy.golang.com.cn,direct
|
- 确认设置:
- 重启vscode,更新VScode的go插件
1
2
3
|
ctrl+shift+p
Go: Install/Update Tools
全选->确认
|
代码格式化
- 打开保存时自动格式化功能:在设置搜索
format on save
,勾选打开
- 选择具体的
link
工具:在设置搜索golint
,选择golangci-lint
- 选择具体的格式化工具:
gofumpt
在设置搜索gopls
,启用gofumpt
1
2
3
|
"gopls": {
"formatting.gofumpt": true
}
|
在设置搜索go format
,选择gofumpt
Debug
go-delve/delve: Delve is a debugger for the Go programming language.
打开要debug的文件,打断点后,单击 VS Code 左侧窗格上的调试图标,点击运行和调式按钮即可