Skip to content

Commit

Permalink
feat: more elaborate health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Sep 2, 2024
1 parent 0d23dc4 commit c2f49c5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
67 changes: 64 additions & 3 deletions lua/crates/health.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,78 @@
local M = {}

local util = require("crates.util")
local state = require("crates.state")

local IS_WIN = vim.api.nvim_call_function("has", { "win32" }) == 1

---@param name string
---@return boolean
local function lualib_installed(name)
local ok = pcall(require, name)
return ok
end

---comment
---@param name string
---@return boolean
local function binary_installed(name)
if IS_WIN then
name = name .. ".exe"
end

return vim.fn.executable(name) == 1
end

function M.check()
vim.health.start("Checking plugins")
if util.lualib_installed("null-ls") then
if lualib_installed("null-ls") then
vim.health.ok("null-ls.nvim installed")
elseif state.cfg.null_ls.enabled then
vim.health.warn("null-ls.nvim not found, but `null_ls.enabled` is set")
else
vim.health.info("null-ls.nvim not found")
end
if state.cfg.lsp.enabled and state.cfg.lsp.actions and state.cfg.null_ls.enabled then
vim.health.warn("lsp actions and null-ls.nvim actions are enabled, only one should be necessary")
end

if lualib_installed("neoconf") then
vim.health.ok("neoconf.nvim installed")
elseif state.cfg.neoconf.enabled then
vim.health.warn("neoconf.nvim not found, but `neoconf.enabled` is set")
else
vim.health.info("neoconf.nvim not found")
end

if lualib_installed("cmp") then
vim.health.ok("nvim-cmp installed")
elseif state.cfg.completion.cmp.enabled then
vim.health.warn("nvim-cmp not found, but `completion.cmp.enabled` is set")
else
vim.health.info("nvim-cmp not found")
end

if lualib_installed("coq") then
vim.health.ok("coq_nvim installed")
elseif state.cfg.completion.coq.enabled then
vim.health.warn("coq_nvim not found, but `completion.coq.enabled` is set")
else
vim.health.info("coq_nvim not found")
end

if state.cfg.lsp.enabled and state.cfg.lsp.completion then
if state.cfg.completion.cmp.enabled then
vim.health.warn("lsp completion and nvim-cmp completion is enabled, only one should be necessary")
end
if state.cfg.completion.coq.enabled then
vim.health.warn("lsp completion and coq_nvim completion is enabled, only one should be necessary")
end
end
if state.cfg.completion.cmp.enabled and state.cfg.completion.coq.enabled then
vim.health.warn("nvim-cmp and coq_nvim completion are enabled, only one should be necessary")
end

vim.health.start("Checking external dependencies")
if util.binary_installed("curl") then
if binary_installed("curl") then
vim.health.ok("curl installed")
else
vim.health.error("curl not found")
Expand Down
20 changes: 0 additions & 20 deletions lua/crates/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ local FeatureInfo = {
}
M.FeatureInfo = FeatureInfo

local IS_WIN = vim.api.nvim_call_function("has", { "win32" }) == 1

---@return integer
function M.current_buf()
return vim.api.nvim_get_current_buf()
Expand Down Expand Up @@ -186,24 +184,6 @@ function M.features_info(crate, features)
return info
end

---@param name string
---@return boolean
function M.lualib_installed(name)
local ok = pcall(require, name)
return ok
end

---comment
---@param name string
---@return boolean
function M.binary_installed(name)
if IS_WIN then
name = name .. ".exe"
end

return vim.fn.executable(name) == 1
end

---comment
---@param severity integer
---@param s string
Expand Down

0 comments on commit c2f49c5

Please sign in to comment.