add health.lua

pull/77/head
ray-x 2 years ago
parent daeaa15e6a
commit 0d5f1c9f31

@ -204,9 +204,9 @@ M.run = function(...)
elseif cfg_exist then
log("using cfg")
launch.load()
for _, cfg in ipairs(dap.configurations.go) do
cfg.dlvToolPath = vim.fn.exepath('dlv')
end
for _, cfg in ipairs(dap.configurations.go) do
cfg.dlvToolPath = vim.fn.exepath("dlv")
end
dap.continue()
else
dap_cfg.program = sep .. "${relativeFileDirname}"

@ -0,0 +1,83 @@
local M = {}
local util = require("go.utils")
local log = util.log
local health = require("health")
local tools = require("go.install").tools
local start = health.report_start
local ok = health.report_ok
local error = health.report_error
local warn = health.report_warn
local info = health.report_info
local function binary_check()
health.report_start("Binaries")
local no_err = true
local go_bin = _GO_NVIM_CFG.go or "go"
if vim.fn.executable(go_bin) == 1 then
info(go_bin .. " installed.")
else
error(go_bin .. " is not installed.")
no_err = false
end
for _, val in ipairs(tools) do
log(val)
if vim.fn.executable(val) == 1 then
info("Tool installed: " .. val)
else
warn("Missing tool: " .. val)
end
end
if no_err then
ok("All binaries installed")
end
end
local function plugin_check()
start("Go Plugin Check")
local plugins = {
"lspconfig",
"nvim-treesitter",
"guihua",
"nvim-dap-virtual-text",
"telescope",
}
local any_warn = false
for _, plugin in ipairs(plugins) do
local pi = util.load_plugin(plugin)
if pi ~= nil then
ok(string.format("%s: plugin is installed", plugin))
else
any_warn = true
warn(string.format("%s: not installed/loaded", plugin))
end
end
plugins = {
["nvim-dap"] = "dap",
["nvim-dap-ui"] = "dapui",
}
for name, req in pairs(plugins) do
local pi = util.load_plugin(name, req)
if pi ~= nil then
ok(string.format("%s: plugin is installed", name))
else
any_warn = true
warn(string.format("%s: not installed/loaded", name))
end
end
if any_warn then
warn("Not all plugin installed")
else
ok("All plugin installed")
end
end
function M.check()
binary_check()
plugin_check()
end
return M

@ -5,7 +5,7 @@ local log = require("go.utils").log
local url = {
gofumpt = "mvdan.cc/gofumpt",
golines = "github.com/segmentio/golines",
golangci_lint = "github.com/golangci/golangci-lint/cmd/golangci-lint",
["golangci-lint"] = "github.com/golangci/golangci-lint/cmd/golangci-lint",
goimports = "golang.org/x/tools/cmd/goimports",
gorename = "golang.org/x/tools/cmd/gorename",
gomodifytags = "github.com/fatih/gomodifytags",
@ -21,9 +21,9 @@ local url = {
richgo = "github.com/kyoh86/richgo",
}
local gotools = {}
local tools = {}
for tool, _ in pairs(url) do
table.insert(gotools, tool)
table.insert(tools, tool)
end
local function is_installed(bin)
local env_path = os.getenv("PATH")
@ -40,7 +40,10 @@ end
local function go_install(pkg)
local u = url[pkg]
if u == nil then
vim.notify("command " .. pkg .. " not supported, please update install.lua, or manually install it", vim.lsp.log_levels.WARN)
vim.notify(
"command " .. pkg .. " not supported, please update install.lua, or manually install it",
vim.lsp.log_levels.WARN
)
return
end
@ -95,5 +98,5 @@ return {
update = update,
install_all = install_all,
update_all = update_all,
gotools = gotools,
tools = tools,
}

@ -338,15 +338,19 @@ function util.load_plugin(name, modulename)
-- packer installed
local loader = require("packer").loader
if not packer_plugins[name] or not packer_plugins[name].loaded then
util.log("packer loader " .. name)
vim.cmd("packadd " .. name) -- load with default
loader(name)
end
else
util.log("packadd " .. name)
vim.cmd("packadd " .. name) -- load with default
end
has, plugin = pcall(require, modulename)
if not has then
util.warn("plugin failed to load " .. name)
return nil
end
return plugin
end

Loading…
Cancel
Save