VSCode conf
快捷键
- 修改同名引用
F2
- 折叠光标处的代码方法
- 折叠所有
Ctrl+K+0
- 展开所有
Ctrl+K+J
- 折叠所有
vscode 配置
在当前工程目录下创建文件
.vscode/launch.json
{
"version": "该配置文件的版本,由 VSCode 自动生成",
"configurations": [
{
"name": "名字,好听就行",
"type": "语言类型,装了插件后填 go 就会调用 dlv 命令",
"request": "launch 是启动新进程,append 是附加到现有的进程",
"mode": "dlv 的一些选项,支持 debug、exec、test、remote",
"host": "dlv 监听的地址",
"port": "dlv 监听的端口(此处应该是数字)",
"program": "本地的程序路径",
"cwd": "当前工作路径",
"env": {
"环境变量名": "环境变量值"
},
"args": ["程序启动参数"],
"showLog": "是否输出 dlv 的日志(此处应该是 true/false)"
}
]
}
演示
-
单个
{ "version": "0.2.0", "configurations": [ { "name": "Debug with dlv", "type": "go", "request": "launch", "mode": "debug", "host": "127.0.0.1", "port": 2345, "program": "${workspaceFolder}/path/to/main.go", "cwd": "${workspaceFolder}", "env": {}, "args": [], "showLog": true } ] }
-
多个
{ "version": "0.2.0", "configurations": [ { "name": "run_normal", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}/main.go", "output": "run_normal", "envFile": "${workspaceRoot}/script/server.env", "env": { "RunType": "1", "ServerId": "yxx_a_1", "GameListen": "0.0.0.0:8000", "GameHttp": "0.0.0.0:8080", }, }, { "name": "run_manager", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}/main.go", "output": "run_manager", "envFile": "${workspaceRoot}/script/server.env", "env": { "RunType": "2", "MGrpc": "0.0.0.0:8022", "MHttp": "0.0.0.0:8021", }, }, { "name": "run_ai", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}/main.go", "output": "run_testing", "envFile": "${workspaceRoot}/script/server.env", "env": { "RunType": "3", "GameListen": "ws://0.0.0.0:8000" }, }, { "name": "run_robot", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}/main.go", "output": "run_testing", "envFile": "${workspaceRoot}/script/server.env", "env": { "RunType": "99", "name": "bt-1-2309189", "gameAddress": "172.12.12.189:19014", "RobotNumber": "2", }, }, ] }
断点
打一个断点,按下 F5,会发现项目已经启动起来了,访问一个 API,发现触发了断点:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
go install github.com/nsf/gocode@latest
go install github.com/uudashr/gopkgs/cmd/gopkgs@latest
go install github.com/ramya-rao-a/go-outline@latest
go install github.com/acroca/go-symbols@latest
go install golang.org/x/tools/cmd/guru@latest
go install golang.org/x/tools/cmd/gorename@latest
go install github.com/fatih/gomodifytags@latest
go install github.com/haya14busa/goplay/cmd/goplay@latest
go install github.com/josharian/impl@latest
go install github.com/davidrjenni/reftools/cmd/fillstruct@latest
go install github.com/rogpeppe/godef@latest
go install golang.org/x/tools/cmd/godoc@latest
go install sourcegraph.com/sqs/goreturns@latest
go install github.com/golang/lint/golint@latest
go install github.com/cweill/gotests/...@latest
go install github.com/derekparker/delve/cmd/dlv@latest
go install github.com/zmb3/gogetdoc@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/ramya-rao-a/go-outline@latest
go install github.com/mdempsky/gocode@latest
go install github.com/rogpeppe/godef@latest
go install golang.org/x/tools/cmd/guru@latest
go install golang.org/x/tools/cmd/gorename@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/uudashr/gopkgs/cmd/gopkgs@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/ramya-rao-a/go-outline@latest
go install github.com/acroca/go-symbols@latest
go install github.com/zmb3/gogetdoc@latest
go install github.com/fatih/gomodifytags@latest
go install github.com/cweill/gotests/...@latest
go install github.com/josharian/impl@latest
go install github.com/uudashr/gopkgs/cmd/gopkgs@latest
go install github.com/davidrjenni/reftools/cmd/fillstruct@latest
go install github.com/ramya-rao-a/go-outline@latest
go install github.com/acroca/go-symbols@latest
go install github.com/mdempsky/gocode@latest
go install github.com/rogpeppe/godef@latest
go install golang.org/x/tools/cmd/godoc@latest
go install github.com/zmb3/gogetdoc@latest
go install golang.org/x/lint/golint@latest
go install github.com/fatih/gomodifytags@latest
go install golang.org/x/tools/cmd/gorename@latest
go install sourcegraph.com/sqs/goreturns@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/cweill/gotests/...@latest
go install golang.org/x/tools/cmd/guru@latest
go install github.com/josharian/impl@latest
go install github.com/haya14busa/goplay/cmd/goplay@latest
go install github.com/uudashr/gopkgs/cmd/gopkgs@latest
go install github.com/davidrjenni/reftools/cmd/fillstruct@latest
go install github.com/alecthomas/gometalinter@latest
This post is licensed under
CC BY 4.0
by the author.