feat: add healthcheck (#9)
* feat: add healthcheck Problem: users had no way to diagnose why completions were missing or incomplete beyond checking for the ghostty executable. Solution: add a :checkhealth module that verifies blink.cmp is installed, ghostty is on PATH, +show-config --docs produces output, and the bash completion file exists for enum values. * fix: revert blanket diagnostics.disable and selene comments Problem: .luarc.json blanket-disabled four diagnostic categories project-wide, and selene inline directives were added to suppress warnings on io.open monkey-patching in tests. Solution: revert .luarc.json to match main and remove selene comments. * refactor: reuse main module's bash completion path resolution in healthcheck Problem: health.lua duplicated the entire bash completion file resolution chain (exepath -> realpath -> prefix match -> path construction) from the main module, risking drift if the logic changes. Solution: extract M.bash_completion_path() from parse_enums() and call it from both parse_enums and the healthcheck.
This commit is contained in:
parent
072859ce04
commit
fe16245881
2 changed files with 60 additions and 5 deletions
|
|
@ -67,21 +67,29 @@ local function parse_keys(stdout)
|
|||
return items
|
||||
end
|
||||
|
||||
---@return table<string, string[]>
|
||||
local function parse_enums()
|
||||
---@return string?
|
||||
function M.bash_completion_path()
|
||||
local bin = vim.fn.exepath('ghostty')
|
||||
if bin == '' then
|
||||
return {}
|
||||
return nil
|
||||
end
|
||||
local real = vim.uv.fs_realpath(bin)
|
||||
if not real then
|
||||
return {}
|
||||
return nil
|
||||
end
|
||||
local prefix = real:match('(.*)/bin/ghostty$')
|
||||
if not prefix then
|
||||
return nil
|
||||
end
|
||||
return prefix .. '/share/bash-completion/completions/ghostty.bash'
|
||||
end
|
||||
|
||||
---@return table<string, string[]>
|
||||
local function parse_enums()
|
||||
local path = M.bash_completion_path()
|
||||
if not path then
|
||||
return {}
|
||||
end
|
||||
local path = prefix .. '/share/bash-completion/completions/ghostty.bash'
|
||||
local fd = io.open(path, 'r')
|
||||
if not fd then
|
||||
return {}
|
||||
|
|
|
|||
47
lua/blink-cmp-ghostty/health.lua
Normal file
47
lua/blink-cmp-ghostty/health.lua
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
local M = {}
|
||||
|
||||
function M.check()
|
||||
vim.health.start('blink-cmp-ghostty')
|
||||
|
||||
local ok = pcall(require, 'blink.cmp')
|
||||
if ok then
|
||||
vim.health.ok('blink.cmp is installed')
|
||||
else
|
||||
vim.health.error('blink.cmp is not installed')
|
||||
end
|
||||
|
||||
local bin = vim.fn.exepath('ghostty')
|
||||
if bin ~= '' then
|
||||
vim.health.ok('ghostty executable found: ' .. bin)
|
||||
else
|
||||
vim.health.error('ghostty executable not found')
|
||||
return
|
||||
end
|
||||
|
||||
local result = vim.system({ 'ghostty', '+show-config', '--docs' }):wait()
|
||||
if result.code == 0 and result.stdout and result.stdout ~= '' then
|
||||
vim.health.ok('ghostty +show-config --docs produces output')
|
||||
else
|
||||
vim.health.warn(
|
||||
'ghostty +show-config --docs failed (config key documentation will be unavailable)'
|
||||
)
|
||||
end
|
||||
|
||||
local source = require('blink-cmp-ghostty')
|
||||
local path = source.bash_completion_path()
|
||||
if not path then
|
||||
vim.health.warn('could not resolve bash completion path (enum completions will be unavailable)')
|
||||
return
|
||||
end
|
||||
local fd = io.open(path, 'r')
|
||||
if fd then
|
||||
fd:close()
|
||||
vim.health.ok('bash completion file found: ' .. path)
|
||||
else
|
||||
vim.health.warn(
|
||||
'bash completion file not found at ' .. path .. ' (enum completions will be unavailable)'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue