无法启动 vimspector 进行远程调试 Docker 容器

Cannot start vimspector for remote debugging Docker container

我正在尝试为远程调试配置 vimspector Python Django 应用程序 运行 在 Docker 容器中,当启动调试器时出现以下错误:

Channel is already running
Error detected while processing function vimspector#Continue[4]..function vimspector#Continue:
line    4:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/.vim/pack/vimspector/opt/vimspector/python3/vimspector/debug_session.py", line 473, in Continue
    self.Start()
  File "~/.vim/pack/vimspector/opt/vimspector/python3/vimspector/debug_session.py", line 277, in Start
    self._StartWithConfiguration( configuration, adapter )
  File "~/.vim/pack/vimspector/opt/vimspector/python3/vimspector/debug_session.py", line 322, in _StartWithConfiguration
    start()
  File "~/.vim/pack/vimspector/opt/vimspector/python3/vimspector/debug_session.py", line 295, in start
    self._Initialise()
  File "~/.vim/pack/vimspector/opt/vimspector/python3/vimspector/debug_session.py", line 972, in _Initialise
    self._connection.DoRequest( handle_initialize_response, {
AttributeError: 'NoneType' object has no attribute 'DoRequest'

这是我的 .vimspector.json 配置文件(主要受 vimspector 文档中的 this example 启发):

{
  "adapters": {
    "python-remote": {
      "port": "${port}",
      "launch": {
        "remote": {
          "container": "${container}",
          "launchCommmand": [
            "python", "-m", "debugpy", "--listen", "0.0.0.0:${port}",
            "%CMD"
          ]
        }
      },
      "attach": {
        "remote": {
          "container": "${container}",
          "pidCommand": [
            "sh", "-c", "pgrep", "-f", "${filename}"
          ],
          "attachCommand": [
            "sh", "-c", "python", "-m", "debugpy", "--listen", "0.0.0.0:${port}",
            "--pid", "%PID%"
          ]
        }
      }
    }
  },
  "configurations": {
    "remote-launch": {
      "adapter": "python-remote",
      "remote-request": "launch",
      "remote-cmdLine": [
        "${RemoteRoot}/${fileBasename}", "*${args}"
      ],
      "configuration": {
        "request": "attach",
        "pathMappings": [
          {
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${RemoteRoot}"
          }
        ]
      }
    },
    "remote-attach": {
      "adapter": "python-remote",
      "remote-request": "attach",

      "configuration": {
        "request": "attach",
        "pathMappings": [
          {
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${RemoteRoot}"
          }
        ]
      }
    }
  }
}

知道是什么原因造成的吗?

回溯显然是一个错误。请参阅 Vimspector 的 CONTRIBUTING.md,了解如何为此报告可重现的测试用例。

我怀疑问题是它没有成功启动调试适配器,然后无法连接到它并陷入混乱。

您可以使用 :VimspectorReset 来“清除”混乱,但重启 vim 可能是清除 vimspector 状态中混乱的唯一方法。

关于连接失败的原因,不太清楚。我们需要知道您到达那里所采取的确切步骤等。最好在 Gitter 频道中寻求对 Vimspector 的支持。

请注意,使用容器时,容器必须已经 运行ning。您告诉 vimspector 容器 ID,它只是 docker exec 使用该 ID。 Vimspector 不是一个容器编排系统,它只是能够 运行 sshdocker exec 命令来帮助您自动化调试过程的某些部分。