Skip to content

Debugging macros with Vimspector in Neovim

Gaël Écorchard edited this page Jun 2, 2023 · 1 revision
  1. In FreeCAD's Python console:
import debugpy
debugpy.configure(python="python")
debugpy.listen(5678)
  1. Configure Neovim to use python as file type for *.FCMacro files:

In vimscript:

au BufNewFile,BufRead *.FCMacro setlocal filetype=python

In lua

vim.filetype.add({
  extension = {
    FCMacro = 'python',
  },
})
  1. File .vimspector.json in a parent directory of the code to debug, for example ~/.local/share/FreeCAD/Macro:
{
  "configurations": {
    "Python: Remote Debug": {
      "adapter": "multi-session",
      "configuration": {
        "name": "Python: Remote Debug",
        "request": "attach",
        "pathMappings": [
          {
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "${workspaceFolder}"
          }
        ]
      }
    }
  }
}
  1. Launch Vimspector ( with Vimspector's "Human" key bindings), set breakpoints and launch the macro in FreeCAD. When asked use localhost for the host and 5678 for the port. Answer other questions to your liking.