vscode 是可定制化程度非常高的编辑器,可玩性很高的同时也带来了一定的门槛

本文以 Go 语言程序为例子介绍实现想要实现如下的功能要如何配置 launch.json

  1. 需要带命令行参数进行调试
  2. 需要控制台持续输入进行调试
  3. 需要同时调试多个进程

vscode 需要带命令行参数进行调试

配置 args 参数,数组中的每个元素会以此放在启动命令后

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/main.go",
"cwd": "${workspaceRoot}",
"args": [
"server",
"-c=settings.mysql.yml"
]
},
],
}

vscode 需要控制台持续输入进行调试

默认会在调试控制台里进行调试,通过配置 console 参数为 “integratedTerminal”,可以使用默认的终端来进行调试,这就能实现在调试的同时在控制台里进行持续输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/main.go",
"cwd": "${workspaceRoot}",
"console": "integratedTerminal"
},
],
}

vscode 需要同时调试多个进程

普通的情况下,每个 configuration 只能启动一个调试进程,这对于微服务开发的时候同时调试多个程序不太友好

可以通过 compounds 参数同时启动多个已经配置好的调试进程

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
{
"version": "0.2.0",
"configurations": [
{
"name": "main1",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/cmd/main1.go",
"cwd": "${workspaceRoot}",
},
{
"name": "main2",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/cmd/main2.go",
"cwd": "${workspaceRoot}",
},
],
"compounds": [
{
"name": "main1/main2",
"configurations": [
"main1",
"main2"
]
}
]
}

资料

Debugging in Visual Studio Code