From 95bf0caf5b2694dc4285b486fd15e5d9ab6c37b1 Mon Sep 17 00:00:00 2001 From: GustavEikaas Date: Thu, 24 Apr 2025 19:13:02 +0200 Subject: [PATCH 1/2] feat: add healthcheck --- lua/code-playground/health.lua | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lua/code-playground/health.lua diff --git a/lua/code-playground/health.lua b/lua/code-playground/health.lua new file mode 100644 index 0000000..8784c9b --- /dev/null +++ b/lua/code-playground/health.lua @@ -0,0 +1,65 @@ +--checkhealth code-playground +local M = {} + +---@param command table +---@param advice string | nil +local function ensure_dep_installed(command, advice) + local exec = command + advice = advice or "" + local success = pcall(function() vim.fn.system(exec) end) + local cmd_name = table.concat(vim.tbl_filter(function(item) return type(item) == "string" and not item:match("^%-") end, exec), " ") + if success and vim.v.shell_error == 0 then + vim.health.ok(cmd_name .. " is installed") + else + print("" .. vim.v.shell_error) + vim.health.error(cmd_name .. " is not installed", { advice }) + end +end + +local function os_info() + local platform = vim.loop.os_uname() + local sysname = platform.sysname + local release = platform.release + + if release:lower():match("arch") then release = release .. " btw" end + + vim.health.info(string.format("%s (%s)", sysname, release)) +end + +local function print_nvim_version() + local v = vim.version() + local version_str = string.format("Neovim version: %d.%d.%d", v.major, v.minor, v.patch) + vim.health.info(version_str) +end + +local function get_shell_info() + local shell = vim.o.shell + vim.health.info("Shell: " .. shell) +end + +local function get_commit_info() + local source = debug.getinfo(1, "S").source:sub(2) + local dir = vim.fn.fnamemodify(source, ":h") + local sha = vim.fn.system({ "git", "-C", dir, "rev-parse", "HEAD" }) + vim.health.info("Commit: " .. vim.trim(sha or "")) +end + +M.check = function() + vim.health.start("General information") + os_info() + print_nvim_version() + get_shell_info() + pcall(get_commit_info) + vim.health.start("CLI dependencies") + ensure_dep_installed({ "cargo", "-h" }, "https://doc.rust-lang.org/cargo/getting-started/installation.html") + ensure_dep_installed({ "odin", "-h" }, "https://odin-lang.org/docs/install/") + ensure_dep_installed({ "go", "-h" }, "https://go.dev/doc/install") + ensure_dep_installed({ "bun", "-h" }, "npm i -g bun") + ensure_dep_installed({ "dotnet", "-h" }, "https://dotnet.microsoft.com/en-us/download") + ensure_dep_installed({ "python", "-h" }, "https://www.python.org/downloads/") + ensure_dep_installed({ "runghc", "-h" }, "https://www.haskell.org/get-started/") + ensure_dep_installed({ "java", "-h" }, "https://www.java.com/en/download/manual.jsp") + ensure_dep_installed({ "zig", "-h" }, "https://ziglang.org/learn/getting-started/") +end + +return M From f7e3744951593b35d0afa06c7f549b03d6612226 Mon Sep 17 00:00:00 2001 From: GustavEikaas Date: Thu, 24 Apr 2025 19:15:49 +0200 Subject: [PATCH 2/2] add path --- lua/code-playground/health.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/code-playground/health.lua b/lua/code-playground/health.lua index 8784c9b..19c7f73 100644 --- a/lua/code-playground/health.lua +++ b/lua/code-playground/health.lua @@ -60,6 +60,8 @@ M.check = function() ensure_dep_installed({ "runghc", "-h" }, "https://www.haskell.org/get-started/") ensure_dep_installed({ "java", "-h" }, "https://www.java.com/en/download/manual.jsp") ensure_dep_installed({ "zig", "-h" }, "https://ziglang.org/learn/getting-started/") + vim.health.start("Plugin information") + vim.health.info("Playground path: " .. vim.fs.joinpath(vim.fs.normalize(vim.fn.stdpath("data")), "code-playground")) end return M