vscode Golang调试launch.json配置

huangapple go评论117阅读模式
英文:

vscode Golang debugging launch.json configuration

问题

尝试使用VSCode调试器来调试我的Go代码。
VSCode使用以下launch.json配置文件来运行同一目录中的所有.go文件:

  1. {
  2. "name": "Test",
  3. "type": "go",
  4. "request": "launch",
  5. "mode": "test",
  6. "program": "${relativeFileDirname}",
  7. }

显然,我尝试将
"program": "${relativeFileDirname}", 改为 "program": "${file}", 但它不起作用。
此外,有没有办法只运行单元测试而不是整个文件(或在这种情况下是整个目录)?

英文:

Trying to use vscode debugger to debug my go code.
vscode runs all the .go files in the same dir using the following launch.json config file:

  1. {
  2. "name": "Test",
  3. "type": "go",
  4. "request": "launch",
  5. "mode": "test",
  6. "program": "${relativeFileDirname}",
  7. }

Obviously, I tried to change
"program": "${relativeFileDirname}", -> "program": "${file}", but it's not working.
In addition, is there a way I can run ut and not the whole file (or in this case the whole dir)?

答案1

得分: 3

你可以使用以下的launch.json配置来运行与.vscode文件夹中的main.go文件相同目录下的文件。将文件名main.go更改为要运行的相应go文件。

{
"version": "0.2.0",
"configurations": [
{
"name": "某个名称",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
}
]
}

英文:

You can use the following launch.json configuration to run the main.go file in the same directory as .vscode. Change the file name main.go to the corresponding go file to run them

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "some name",
  6. "type": "go",
  7. "request": "launch",
  8. "mode": "auto",
  9. "program": "main.go",
  10. }
  11. ]
  12. }

huangapple
  • 本文由 发表于 2022年7月19日 23:11:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/73039438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定