是否可以从 Visual Studio 代码调试 go revel 框架?

Is it possible to debug go revel framework from Visual Studio Code?

我正在尝试使用 visual studio 调试 Revel 应用程序,但无法正常工作。

我看过这个问题how to debug revel framework(golang) application in visual studio code(vscode)但还没有答案...

我试过这个配置:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "remotePath": "",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "~/code/go/bin/revel",
      "env": {},
      "args": [],
      "showLog": true
    }
  ]
}

但是我收到了这个错误: Failed to continue: "The program attribute must point to valid directory, .go file or executable."

我认为它一定是 rebel 二进制文件,这里是 运行,但我不知道如何传递应用程序路径,它应该进入 "args" 吗?

是的,这是可能的。

  1. 假设 GOPATHC:\Work\golang
  2. Revel 项目名称为 myapp,因此项目(工作区)的位置将为 C:\Work\golang\src\myapp
  3. 对控制器等进行一些更改...
  4. 运行应用revel run myapp,然后按CTRL+C退出。这一步是生成相应的go文件所必需的。生成的文件,即 main 包将在 ${workspaceRoot}/app/tmp/main.go
  5. 下可用
  6. 配置launch.json如下:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "env": {},
                "showLog": true,
                "program": "${workspaceRoot}/app/tmp/",
                "args": ["-importPath", "myapp", "-srcPath", "c:\work\golang\src",  "-runMode", "dev"]
            }
        ]
    }
    
  7. 重要的部分是programargs参数,其他参数不用修改。

  8. 设置breakpoint并启动delve调试器...

编辑:

  1. args 参数设置为 ["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"] 也有效,我认为这在其他平台(Mac、Linux)中也应该有效。
  2. 错误消息与 delve 问题有关。参见 https://github.com/Microsoft/vscode-go/issues/986