My-Linux-Config icon indicating copy to clipboard operation
My-Linux-Config copied to clipboard

How to debug with neovim?

Open flyingTan opened this issue 3 years ago • 10 comments

你好,我对 SpaceVim 不是很熟悉,我现在已经安装 SpaceVim、ccls,看了几遍你文档和官方文档,但还是有些无从下手,麻烦有时间解答一下。我想实现以下功能:

【1】 Python 光标位置显示定义 Common(类似于 VScode intelligence); 【2】 Python 带有有参数的 Debug。 【3】 可交互式的 Debug。

目前已有配置如下:

image

因为对 VIM 不是特别熟悉,请帮忙尽可能详细描述一下配置步骤。

flyingTan avatar Mar 29 '21 09:03 flyingTan

【1】 Python 光标位置显示定义 Common(类似于 VScode intelligence);

这个功能我不知道是什么效果? 可以给我一个在 VScode 中间的截图吗 ?

【2】 Python 带有有参数的 Debug。 【3】 可交互式的 Debug。

其实我从来没有 DEBUG 过 Python 代码。在 vim 中间我尝试调试过 C 语言,后来就没有用了,现在一般是直接在终端中间使用 gdb,具体的尝试我在文档中间写过了。

On Mon, Mar 29, 2021 at 5:16 PM flyingTan @.***> wrote:

Assigned #14 https://github.com/Martins3/My-Linux-config/issues/14 to @Martins3 https://github.com/Martins3.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Martins3/My-Linux-config/issues/14#event-4520305115, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7UY3DO7EUOCKUWXELDV2LTGBAPNANCNFSM4Z7F5PVQ .

Martins3 avatar Mar 29 '21 09:03 Martins3

调试这个东西我确实一直都没太注意,趁这次把这个修复一下也是极好的。关于调试的配置,你有找到什么资料或者想法吗 ?

On Mon, Mar 29, 2021 at 5:45 PM Bachelar Hu @.***> wrote:

【1】 Python 光标位置显示定义 Common(类似于 VScode intelligence);

这个功能我不知道是什么效果? 可以给我一个在 VScode 中间的截图吗 ?

【2】 Python 带有有参数的 Debug。 【3】 可交互式的 Debug。

其实我从来没有 DEBUG 过 Python 代码。在 vim 中间我尝试调试过 C 语言,后来就没有用了,现在一般是直接在终端中间使用 gdb,具体的尝试我在文档中间写过了。

On Mon, Mar 29, 2021 at 5:16 PM flyingTan @.***> wrote:

Assigned #14 https://github.com/Martins3/My-Linux-config/issues/14 to @Martins3 https://github.com/Martins3.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/Martins3/My-Linux-config/issues/14#event-4520305115, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7UY3DO7EUOCKUWXELDV2LTGBAPNANCNFSM4Z7F5PVQ .

Martins3 avatar Mar 29 '21 09:03 Martins3

很抱歉,我在这方面貌似没你专业,因为我平时用 VScode 等 IDE 比较多,所以现在用你配置有点棘手,有点无从下手。本质问题在与中间很多工作没做到位,所以向你请教一种循序渐进的方法。但是又没太多想法,只能硬看。

  • 平时debug python 用的就是 ipdb,和gdb 差不多比较原始,高级用法我没涉猎。

flyingTan avatar Mar 29 '21 13:03 flyingTan

问题不大,我周末的时候看看这个有没有好的解决方案。

On Mon, Mar 29, 2021 at 9:59 PM flyingTan @.***> wrote:

很抱歉,我在这方面貌似没你专业,因为我平时用 VScode 等 IDE 比较多,所以现在用你配置有点棘手,有点无从下手。本质问题在与中间很多工作没做到位,所以向你请教一种循序渐进的方法。,但是又没太多想法,只能硬看。

  • 平时debug python 用的就是 ipdb,和gdb 差不多比较原始。高级用法我没涉猎。

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Martins3/My-Linux-config/issues/14#issuecomment-809399777, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7UY3E7JKC5OX7IAQRY44LTGCBUFANCNFSM4Z7F5PVQ .

Martins3 avatar Mar 29 '21 14:03 Martins3

使用这个项目配置的,下面是调试 CPP 的效果。具体的配置还需要打磨一下。

image

Martins3 avatar Mar 31 '21 12:03 Martins3

写一下我自己的想法:

  1. 两个框架的作者都是准备集成这个 vimspector 的
  • https://github.com/SpaceVim/SpaceVim/issues/3294
  • https://github.com/neoclide/coc.nvim/issues/322
  1. 我自己尝试了一些,配置并不是很难,主要是很多快捷键需要重新映射
➜  test git:(master) ✗ cat .vimspector.json
{
  "configurations": {
    "Vim - run a test": {
      "adapter": "vscode-cpptools",
      "configuration": {
        "type":    "cppdbg",
        "request": "launch",
        "program": "${workspaceRoot}/a.out",
        "args": [
        ],
        "cwd": "${workspaceRoot}",
        "environment": [
          { "name": "runtime", "value": "${workspaceRoot}/runtime" }
        ],
        "externalConsole": true,
        "stopAtEntry": true,
        "MIMode": "gdb",
        "logging": {
          "engineLogging": false
        }
      }
    }
  }
}
  1. vimspector 的设计 vscode 很类似
  2. 在我的文中提到过几种 gdb 的强化产品,我个人感觉可以很大的挽救调试的体验,所以 vimspector 的使用并没有那么紧迫。

综合上面的内容,我不想自己写一个 vimspector 成为现在 coc.nvim / spsacevim 尚未集成 vimspector 的过渡品。

Martins3 avatar Apr 20 '21 01:04 Martins3

值得关注的项目:

  • https://github.com/mfussenegger/nvim-dap
  • https://github.com/rcarriga/nvim-dap-ui
  • https://github.com/sakhnik/nvim-gdb

Martins3 avatar Sep 14 '21 16:09 Martins3

这个人花了三天才才配置好,看来到如今,在 nvim 中还是比较难集成调试https://www.reddit.com/r/neovim/comments/silikv/debugging_in_neovim/

Martins3 avatar Feb 02 '22 14:02 Martins3

https://github.com/Martins3/My-Linux-Config/tree/debug 在这个分支中简单测试 dap 的功能,基本上可以说是开箱即用,但是:

  1. ARM MAC 不支持
  2. nixos 不支持
  3. 需要引入超级多配置
  4. 引入非 mainstream 的插件

我建议如果没有额外的精力,可以再等一年

Martins3 avatar Oct 15 '22 14:10 Martins3

  • https://github.com/jbyuki/one-small-step-for-vimkind
  • https://github.com/nvim-lua/kickstart.nvim/blob/master/lua/kickstart/plugins/debug.lua
  • https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation

Martins3 avatar Sep 08 '23 14:09 Martins3