Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix health check #248

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions lua/scnvim/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ local M = {}
local function check_nvim_version()
local supported = vim.fn.has 'nvim-0.7' == 1
if not supported then
health.report_error 'scnvim needs nvim version 0.7 or higher.'
health.report_info 'if you are unable to upgrade, use the `0.6-compat` branch'
health.error 'scnvim needs nvim version 0.7 or higher.'
health.info 'if you are unable to upgrade, use the `0.6-compat` branch'
else
local v = vim.version()
health.report_ok(string.format('nvim version %d.%d.%d', v.major, v.minor, v.patch))
health.ok(string.format('nvim version %d.%d.%d', v.major, v.minor, v.patch))
end
end

local function check_classes_installed()
local class_path = install.check()
if not class_path then
health.report_error 'scnvim classes are not installed.'
health.report_info 'use `ensure_installed = true` in the scnvim setup function'
health.error 'scnvim classes are not installed.'
health.info 'use `ensure_installed = true` in the scnvim setup function'
else
health.report_ok('scnvim classes are installed: ' .. class_path)
health.ok('scnvim classes are installed: ' .. class_path)
end
end

local function check_keymaps()
if vim.tbl_count(config.keymaps) == 0 then
health.report_info 'no keymaps defined'
health.info 'no keymaps defined'
else
health.report_ok 'keymaps are defined'
health.ok 'keymaps are defined'
end
end

local function check_documentation()
local doc = config.documentation
if not doc.cmd then
health.report_info 'using HelpBrowser for documentation'
health.info 'using HelpBrowser for documentation'
else
local exe_path = vim.fn.exepath(doc.cmd)
if exe_path ~= '' then
health.report_ok(doc.cmd)
health.ok(doc.cmd)
end
if doc.args then
local vin = false
Expand All @@ -60,30 +60,30 @@ local function check_documentation()
end
end
if vin and vout then
health.report_ok(vim.inspect(doc.args))
health.ok(vim.inspect(doc.args))
elseif vout and not vin then
health.report_error 'argument list is missing input placeholder ($1)'
health.error 'argument list is missing input placeholder ($1)'
elseif vin and not vout then
health.report_error 'argument list is missing output placeholder ($2)'
health.error 'argument list is missing output placeholder ($2)'
else
health.report_error 'argument list is missing both input and output placeholders ($1/$2)'
health.error 'argument list is missing both input and output placeholders ($1/$2)'
end
end
if doc.on_open then
health.report_info 'using external function for on_open'
health.info 'using external function for on_open'
end
if doc.on_select then
health.report_info 'using external function for on_select'
health.info 'using external function for on_select'
end
end
end

local function check_sclang()
local ok, ret = pcall(sclang.find_sclang_executable)
if ok then
health.report_ok('sclang executable: ' .. ret)
health.ok('sclang executable: ' .. ret)
else
health.report_error(ret)
health.error(ret)
end
end

Expand All @@ -96,29 +96,29 @@ local function check_extensions()
for _, name in ipairs(installed) do
local health_check = extensions._health[name]
if health_check then
health.report_start(string.format('extension: "%s"', name))
health.start(string.format('extension: "%s"', name))
health_check()
local link = extensions._linked[name]
if link then
health.report_ok(string.format('installed classes "%s"', link))
health.ok(string.format('installed classes "%s"', link))
else
health.report_ok 'no classes to install'
health.ok 'no classes to install'
end
else
health.report_ok(string.format('No health check for "%s"', name))
health.ok(string.format('No health check for "%s"', name))
end
end
end

function M.check()
health.report_start 'scnvim'
health.start 'scnvim'
check_nvim_version()
check_sclang()
check_classes_installed()
check_keymaps()
health.report_start 'scnvim documentation'
health.start 'scnvim documentation'
check_documentation()
health.report_start 'scnvim extensions'
health.start 'scnvim extensions'
check_extensions()
end

Expand Down