--[[ 50-dap.lua — debug Lua running inside Neovim via OSV (one-small-step-for-vimkind). Wires nvim-dap to the OSV adapter so the running Neovim instance can be attached to and debugged. User commands: `OSVLaunch`: start the OSV server (on the debuggee) `OSVStatus`: show the status of the OSV server and client ]] local dap = require("dap") local osv = require("osv") -- Port shared by the OSV server and the dap attach configuration. local OSV_PORT = 8086 ---------------------------------------------------------------------------------------------------- -- OSV (Lua inside Neovim) ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- -- Start the OSV server so the running Neovim instance can be attached to. local function osv_launch() osv.launch({ port = OSV_PORT }) end -- Report whether the OSV server is running and whether a client is attached. local function osv_status() vim.notify("OSV server running: " .. tostring(osv.is_running())) vim.notify("OSV client attached: " .. tostring(osv.is_attached())) end ---------------------------------------------------------------------------------------------------- -- Configuration & commands ------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------------- --[[ The cast restores dap.configurations' own type: with fzf-lua in the lua_ls library its dap provider cross-merges a `configurations` field, which otherwise mistypes this as a function. ]] local configurations = dap.configurations --[[@as table]] configurations.lua = { { type = "nlua", request = "attach", name = "Attach to running Neovim instance", port = OSV_PORT, }, } dap.adapters.nlua = function(callback, config) callback({ type = "server", host = config.host or "127.0.0.1", port = config.port }) end vim.api.nvim_create_user_command("OSVLaunch", osv_launch, { desc = "Launch OSV server" }) vim.api.nvim_create_user_command("OSVStatus", osv_status, { desc = "Show OSV status" })