Skip to content

Commit

Permalink
Add health check
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed May 30, 2024
1 parent 7b18c31 commit 5ba8cea
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions lua/dap/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
local M = {}

---@param command string?
local function check_executable(command)
local health = vim.health
if not command then
health.error("Missing required `command` property")
else
if vim.fn.executable(command) ~= 1 then
health.error(table.concat({
"`command` is not executable.",
"Check path and permissions.",
"Use vim.fn.expand to handle ~ or $HOME:\n ",
command
}, " "))
else
health.ok("is executable: " .. command)
end
end
end


function M.check()
local health = vim.health
if not health or not health.start then
return
end
health.start("dap: Adapters")
local dap = require("dap")
for t, adapter in pairs(dap.adapters) do
health.start("dap.adapter: " .. t)
if type(adapter) == "function" then
health.info("Adapter is a function. Can't validate it")
else
if adapter.type == "executable" then
adapter = adapter --[[@as ExecutableAdapter]]
check_executable(adapter.command)
elseif adapter.type == "server" then
adapter = adapter --[[@as ServerAdapter]]
if not adapter.port then
health.error("Missing required `port` property")
end
if adapter.executable then
check_executable(adapter.executable.command)
end
elseif adapter.type == "pipe" then
adapter = adapter --[[@as PipeAdapter]]
if not adapter.pipe then
health.error("Missing required `pipe` property")
end
else
health.error(adapter.type .. " must be one of: executable, server or pipe")
end
end
end

health.start("dap: Sessions")
local sessions = dap.sessions()
if not next(sessions) then
health.ok("No active sessions")
else
for _, session in pairs(sessions) do
if session.initialized then
health.ok(" id: " .. session.id .. "\n type: " .. session.config.type)
else
health.warn(table.concat({
"\n id: ", session.id,
"\n type: ", session.config.type,
"\n started, but not initialized. ",
"Either the adapter definition or the used configuration is wrong, ",
"or the defined adapter doesn't speak DAP",
}))
end
end
end
end


return M

0 comments on commit 5ba8cea

Please sign in to comment.