鼠标支持 dap-mouse

注意:

  • dap-mouse 与 lsp-mode 和 lsp-treemacs 关联
  • 使用 lsp-bridge-mode 启用 dap-mouse 无效

启用方法:

1
2
(dap-tooltip-mode +1)
(tooltip-mode +1)

延迟时间:

1
(setq tooltip-delay 0.2)

launch.json

  • configuration 属性
  • 变量

    ${workspaceFolder}
    项目根目录
    {$file}
    当前打开的 editor 显示文件
    {$env:variable_name}

    环境变量

    • {$env:hostname}
  • 例子

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "skipFiles": ["<node_internals>/**"],
                "program": "${workspaceFolder}\\app.js"
            }
        ]
    }

request 字段

  • 两种取值

    • launch 类型

      • 用途:新启动一个 process, 对其 debug
    • attach 类型

      • 用途:已经启动的 process, 对其 debug

debug 进入 library 代码

参考:Visual Studio Code - Python debugging - Step into the code of external functi…

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
    //    ...,
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false // 允许进入非项目代码
        }
    ]
}

configuration 配置

参考:Configuration - DAP Mode

创建 debug 配置模板

对应 vscode debug 配置文件: Run –> Add Configuration

修改模板: M-x dap-debug-edit-template

示例:

1
2
3
4
5
6
7
8
9
(dap-register-debug-template
  "Python :: Run file (buffer)"
  (list :type "python"
        :args ""
        :cwd nil
        :module nil
        :program nil
        :request "launch"
        :name "Python :: Run file (buffer)"))

debug library

设置字段 justMyCode: false

验证无效

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
(dap-register-debug-template
  "Python :: Run file (buffer) step in to library"
  (list :type "python"
        :args ""
        :cwd nil
        :module nil
        :program nil
        :request "launch"
        :name "Python :: Run file (buffer)"
        :justMyCode :json-false))

设置字段 "debugStdLib": true

测试不可行,适合 vscode 不适合 dap-mode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(dap-register-debug-template
  "Python :: Run file debug library"
  (list :type "python"
        :args ""
        :cwd nil
        :module nil
        :program nil
        :request "launch"
        :name "Python :: Run file (buffer)"
        :justMyCode :json-false
        :debugStdLib :json-true))

设置 debugOptions 字段

参考: github issue 评论

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(dap-register-debug-template
  "Python :: Debug library"
  (list :type "python"
        :args ""
        :cwd nil
        :module nil
        :program nil
        :request "launch"
        :name "Python :: Debug library"
        :justMyCode :json-false
        :debugOptions ["DebugStdLib" "ShowReturnValue" "RedirectOutput" ]))

python dap

参考

templates

debug current module

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(defun my/dap-python-register-dynamic ()
    (interactive)
    (dap-register-debug-template "Python: This Module"
                                 (list :type "python"
                                       :cwd (my/get-project-root)
                                       :module (my/python-get-module-name-cmd)
                                       :env '(("DEBUG" . "1"))
                                       :request "launch"
                                       :justMyCode t
                                       :name (format "Python: This Module" (my/python-get-module-name-cmd)))
                                 ))

FAQ

debugpy 本身: typeError 异常

参考:

异常描述

1
2
3
  File "/Users/mikael/Develop/.virtualenvs/pyvenv3.9/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py", line 281, in make_get_thread_stack_message
    end = min(start + levels, total_frames)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

解决方法:

1
pip install git+https://github.com/microsoft/debugpy.git@78b030f5092d91df64860914962333e89852ea9b
  • 更换 debugpy