From f507a37a72691262a20f98029d0392532fdac0ea Mon Sep 17 00:00:00 2001 From: Smirnov Olexander Date: Mon, 6 Jun 2022 23:53:50 +0300 Subject: [PATCH] feat: add health checker --- autoload/health/gopher.vim | 3 +++ lua/gopher/_utils/init.lua | 17 +++++++++++++++++ lua/gopher/health.lua | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 autoload/health/gopher.vim create mode 100644 lua/gopher/health.lua diff --git a/autoload/health/gopher.vim b/autoload/health/gopher.vim new file mode 100644 index 0000000..7ff5205 --- /dev/null +++ b/autoload/health/gopher.vim @@ -0,0 +1,3 @@ +function! health#gopher#check() + lua require"gopher.health".check() +endfunction diff --git a/lua/gopher/_utils/init.lua b/lua/gopher/_utils/init.lua index e2c4d07..aa4537f 100644 --- a/lua/gopher/_utils/init.lua +++ b/lua/gopher/_utils/init.lua @@ -19,4 +19,21 @@ return { return s:sub(1, n) end, + + ---@param lib string + ---@return boolean + lualib_is_found = function(lib) + local is_found, _ = pcall(require, lib) + return is_found + end, + + ---@param bin string + ---@return boolean + binary_is_found = function(bin) + if vim.fn.executable(bin) == 1 then + return true + end + + return false + end, } diff --git a/lua/gopher/health.lua b/lua/gopher/health.lua new file mode 100644 index 0000000..99a6c5b --- /dev/null +++ b/lua/gopher/health.lua @@ -0,0 +1,35 @@ +local utils = require "gopher._utils" +local M = { + _required = { + plugins = { + { lib = "plenary" }, + { lib = "nvim-treesitter" }, + }, + binarys = { + { bin = "go", help = "required for GoMod command" }, + { bin = "gomodifytags", help = "required for modify struct tags" }, + }, + }, +} + +function M.check() + vim.health.report_start "Required plugins" + for _, plugin in ipairs(M._required.plugins) do + if utils.lualib_is_found(plugin.lib) then + vim.health.report_ok(plugin.lib .. " installed.") + else + vim.health.report_error(plugin.lib .. " not found. Gopher.nvim will not work without it!") + end + end + + vim.health.report_start "Required go tools" + for _, binary in ipairs(M._required.binarys) do + if utils.binary_is_found(binary.bin) then + vim.health.report_ok(binary.bin .. " installed") + else + vim.health.report_warn(binary.bin .. " is not installed but " .. binary.help) + end + end +end + +return M