You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已配置launch.json环境变量,VS Code仍无法找到Delve调试器

问题

我的launch.json配置如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch test function",
            "type": "go",
            "request": "launch",
            "mode": "test",
            "program": "${workspaceFolder}/checkers/x/checkers/keeper",
            "args": [
           
            ],
            "env": {"GOPATH":"/home/alain/go", "PATH":"/home/alain/go/bin", "GO15VENDOREXPERIMENT": 1}
        }
   
    ]
}

dlv二进制文件位于/home/alain/go/bin目录,终端中无论是否在该目录下都能正常运行。但在VS Code中启动调试时,仍收到错误提示:

Failed to continue "Cannot find delve debugger. Install from https://github.com/go-delve/delve & ensure it is in your Go tools path, "GOPATH/bin" or "PATH"

已安装Delve。

可能的解决方法
  • 直接指定dlv路径
    在launch.json的配置项里添加dlvPath字段,明确指向dlv的绝对路径:
{
    "name": "Launch test function",
    "type": "go",
    "request": "launch",
    "mode": "test",
    "program": "${workspaceFolder}/checkers/x/checkers/keeper",
    "args": [],
    "env": {"GOPATH":"/home/alain/go", "PATH":"/home/alain/go/bin", "GO15VENDOREXPERIMENT": 1},
    "dlvPath": "/home/alain/go/bin/dlv"
}
  • 检查VS Code的环境变量
    打开VS Code内置终端,执行echo $PATH,确认/home/alain/go/bin是否在输出中。如果不在,重启VS Code(建议从终端启动VS Code,这样会继承终端的环境变量)。
  • 配置Go插件的Delve路径
    打开VS Code设置,搜索Go: Delve Path,手动填入/home/alain/go/bin/dlv,保存后重新尝试调试。
  • 确认dlv权限
    执行命令chmod +x /home/alain/go/bin/dlv,确保dlv具备可执行权限。

内容的提问来源于stack exchange,提问作者a6i09per5f

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 12:35:15