REFACTOR: I spent all day on it but I am heavily refactoring the API and
organization because it was terrible before and hard to maintain. Now it should be much easier and there is still of a design decisions to figure out
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
local ok, health = pcall(require, "vim.health")
|
||||
if not ok then
|
||||
health = nil
|
||||
end
|
||||
|
||||
local new_api = health ~= nil and type(health.start) == "function"
|
||||
|
||||
local function report_start(name)
|
||||
if new_api then health.start(name) else vim.health.report_start(name) end
|
||||
end
|
||||
|
||||
local function report_ok(msg)
|
||||
if new_api then health.ok(msg) else vim.health.report_ok(msg) end
|
||||
end
|
||||
|
||||
local function report_info(msg)
|
||||
if new_api then health.info(msg) else vim.health.report_info(msg) end
|
||||
end
|
||||
|
||||
local function report_warn(msg, advice)
|
||||
if new_api then
|
||||
health.warn(msg, advice)
|
||||
else
|
||||
vim.health.report_warn(msg, advice)
|
||||
end
|
||||
end
|
||||
|
||||
local function report_error(msg, advice)
|
||||
if new_api then
|
||||
health.error(msg, advice)
|
||||
else
|
||||
vim.health.report_error(msg, advice)
|
||||
end
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
local function fmt_langs(langs)
|
||||
if type(langs) == "table" then
|
||||
return "[" .. table.concat(langs, ", ") .. "]"
|
||||
end
|
||||
return "[" .. tostring(langs) .. "]"
|
||||
end
|
||||
|
||||
local function check_nvim_version()
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
report_ok(string.format("Neovim %s detected.", tostring(vim.version())))
|
||||
else
|
||||
report_error("Polydev requires Neovim 0.10 or newer.", "You are running " .. tostring(vim.version()))
|
||||
end
|
||||
end
|
||||
|
||||
local function check_setup()
|
||||
local ok_configs, configs = pcall(require, "Polydev.configs")
|
||||
if not ok_configs then
|
||||
report_error("Could not load Polydev.configs", tostring(configs))
|
||||
return nil
|
||||
end
|
||||
if next(configs.user_config or {}) == nil then
|
||||
report_warn("Polydev.setup() has not run.",
|
||||
"Add require('Polydev').setup() to your Neovim config, or make sure plugin/Polydev.lua is sourced by your plugin manager.")
|
||||
return nil
|
||||
end
|
||||
report_ok("Polydev.setup() ran and the config is loaded.")
|
||||
return configs
|
||||
end
|
||||
|
||||
local function check_project_root(configs)
|
||||
if not configs then return end
|
||||
local root = configs.get("globals").project_root
|
||||
local expanded = vim.fn.expand(root)
|
||||
if vim.fn.isdirectory(expanded) == 1 then
|
||||
if vim.fn.filewritable(expanded) == 2 then
|
||||
report_ok(string.format("project_root exists and is writable: %s", expanded))
|
||||
else
|
||||
report_warn(string.format("project_root exists but is not writable: %s", expanded))
|
||||
end
|
||||
else
|
||||
report_warn(string.format("project_root does not exist yet: %s", expanded),
|
||||
"It is created automatically the first time the manager is opened.")
|
||||
end
|
||||
end
|
||||
|
||||
local function check_ui_input()
|
||||
local ok_default, default = pcall(require, "vim.ui")
|
||||
if ok_default and default.input and vim.ui.input ~= default.input then
|
||||
report_warn("vim.ui.input has been overridden, likely by a UI plugin such as dressing.nvim or nui.nvim.",
|
||||
"An asynchronous override can break project/file creation from the manager. Polydev now uses callbacks, but report here if it still misbehaves.")
|
||||
else
|
||||
report_ok("vim.ui.input is Neovim's default (synchronous) implementation.")
|
||||
end
|
||||
end
|
||||
|
||||
local function check_tools()
|
||||
local tools = {
|
||||
{ name = "git", langs = "all" },
|
||||
{ name = "node", langs = "javascript" },
|
||||
{ name = "python3", langs = "python" },
|
||||
{ name = "pip3", langs = "python" },
|
||||
{ name = "javac", langs = "java" },
|
||||
{ name = "java", langs = "java" },
|
||||
{ name = "cmake", langs = { "c", "cpp" } },
|
||||
{ name = "cc", langs = { "c", "cpp" } },
|
||||
{ name = "clang", langs = { "c", "cpp" } },
|
||||
{ name = "clang-format", langs = { "c", "cpp" } },
|
||||
{ name = "clang-tidy", langs = { "c", "cpp" } },
|
||||
{ name = "cargo", langs = "rust" },
|
||||
{ name = "lua", langs = "lua" },
|
||||
{ name = "luajit", langs = "lua" },
|
||||
}
|
||||
for _, t in ipairs(tools) do
|
||||
if vim.fn.executable(t.name) == 1 then
|
||||
report_ok(string.format("%s is available for %s.", t.name, fmt_langs(t.langs)))
|
||||
else
|
||||
report_warn(string.format("%s was not found.", t.name),
|
||||
"Project templates for " .. fmt_langs(t.langs) .. " may fail without it.")
|
||||
end
|
||||
end
|
||||
|
||||
if vim.fn.executable("python3") == 1 then
|
||||
vim.fn.system("python3 -c 'import venv' 2>/dev/null")
|
||||
if vim.v.shell_error == 0 then
|
||||
report_ok("python3 venv module is available.")
|
||||
else
|
||||
report_warn("python3 venv module is missing.",
|
||||
"Python project creation sets up a virtualenv and needs python3 -m venv.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function check_walkup()
|
||||
local scripts = vim.api.nvim_get_runtime_file("bash_scripts/walkup.sh", false)
|
||||
if #scripts == 0 then
|
||||
report_error("bash_scripts/walkup.sh was not found on the runtimepath.",
|
||||
"Reinstall the plugin so bash_scripts/ sits next to lua/ and plugin/.")
|
||||
return
|
||||
end
|
||||
local script = scripts[1]
|
||||
if vim.fn.executable(script) == 1 then
|
||||
report_ok(string.format("bash_scripts/walkup.sh found and executable: %s", script))
|
||||
else
|
||||
report_warn(string.format("bash_scripts/walkup.sh is not executable: %s", script),
|
||||
"Run: chmod +x " .. script)
|
||||
end
|
||||
end
|
||||
|
||||
function M.check()
|
||||
report_start("Polydev")
|
||||
check_nvim_version()
|
||||
local configs = check_setup()
|
||||
check_project_root(configs)
|
||||
check_ui_input()
|
||||
check_tools()
|
||||
check_walkup()
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user