|
| 1 | +local M = {} |
| 2 | + |
| 3 | +---@param command string? |
| 4 | +local function check_executable(command) |
| 5 | + local health = vim.health |
| 6 | + if not command then |
| 7 | + health.error("Missing required `command` property") |
| 8 | + else |
| 9 | + if vim.fn.executable(command) ~= 1 then |
| 10 | + health.error(table.concat({ |
| 11 | + "`command` is not executable.", |
| 12 | + "Check path and permissions.", |
| 13 | + "Use vim.fn.expand to handle ~ or $HOME:\n ", |
| 14 | + command |
| 15 | + }, " ")) |
| 16 | + else |
| 17 | + health.ok("is executable: " .. command) |
| 18 | + end |
| 19 | + end |
| 20 | +end |
| 21 | + |
| 22 | + |
| 23 | +function M.check() |
| 24 | + local health = vim.health |
| 25 | + if not health or not health.start then |
| 26 | + return |
| 27 | + end |
| 28 | + health.start("dap: Adapters") |
| 29 | + local dap = require("dap") |
| 30 | + for t, adapter in pairs(dap.adapters) do |
| 31 | + health.start("dap.adapter: " .. t) |
| 32 | + if type(adapter) == "function" then |
| 33 | + health.info("Adapter is a function. Can't validate it") |
| 34 | + else |
| 35 | + if adapter.type == "executable" then |
| 36 | + adapter = adapter --[[@as ExecutableAdapter]] |
| 37 | + check_executable(adapter.command) |
| 38 | + elseif adapter.type == "server" then |
| 39 | + adapter = adapter --[[@as ServerAdapter]] |
| 40 | + if not adapter.port then |
| 41 | + health.error("Missing required `port` property") |
| 42 | + end |
| 43 | + if adapter.executable then |
| 44 | + check_executable(adapter.executable.command) |
| 45 | + end |
| 46 | + elseif adapter.type == "pipe" then |
| 47 | + adapter = adapter --[[@as PipeAdapter]] |
| 48 | + if not adapter.pipe then |
| 49 | + health.error("Missing required `pipe` property") |
| 50 | + end |
| 51 | + else |
| 52 | + health.error(adapter.type .. " must be one of: executable, server or pipe") |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + health.start("dap: Sessions") |
| 58 | + local sessions = dap.sessions() |
| 59 | + if not next(sessions) then |
| 60 | + health.ok("No active sessions") |
| 61 | + else |
| 62 | + for _, session in pairs(sessions) do |
| 63 | + if session.initialized then |
| 64 | + health.ok(" id: " .. session.id .. "\n type: " .. session.config.type) |
| 65 | + else |
| 66 | + health.warn(table.concat({ |
| 67 | + "\n id: ", session.id, |
| 68 | + "\n type: ", session.config.type, |
| 69 | + "\n started, but not initialized. ", |
| 70 | + "Either the adapter definition or the used configuration is wrong, ", |
| 71 | + "or the defined adapter doesn't speak DAP", |
| 72 | + })) |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | +end |
| 77 | + |
| 78 | + |
| 79 | +return M |
0 commit comments