Skip to content

Commit

Permalink
feat: add health.lua and basic healthchecks (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry authored Oct 13, 2024
1 parent b378d50 commit a12617d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lua/blink/cmp/fuzzy/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function download.get_lib_extension()
end

local root_dir = debug.getinfo(1).source:match('@?(.*/)')
local lib_path = root_dir .. '../../../../target/release/libblink_cmp_fuzzy' .. download.get_lib_extension()
download.lib_path = root_dir .. '../../../../target/release/libblink_cmp_fuzzy' .. download.get_lib_extension()
local version_path = root_dir .. '../../../../target/release/version.txt'

--- @param callback fun(err: string | nil)
Expand Down Expand Up @@ -58,12 +58,15 @@ end

--- @param cb fun(downloaded: boolean)
function download.is_downloaded(cb)
vim.uv.fs_stat(lib_path, function(err)
vim.uv.fs_stat(download.lib_path, function(err)
if not err then
cb(true)
else
-- If not found, check without 'lib' prefix
vim.uv.fs_stat(string.gsub(lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'), function(error) cb(not error) end)
vim.uv.fs_stat(
string.gsub(download.lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'),
function(error) cb(not error) end
)
end
end)
end
Expand Down Expand Up @@ -97,7 +100,7 @@ function download.from_github(tag, cb)
.. system_triple
.. download.get_lib_extension()

vim.system({ 'curl', '--create-dirs', '-Lo', lib_path, url }, {}, function(out)
vim.system({ 'curl', '--create-dirs', '-Lo', download.lib_path, url }, {}, function(out)
if out.code ~= 0 then cb('Failed to download pre-build binaries: ' .. out.stderr) end
cb()
end)
Expand Down
35 changes: 35 additions & 0 deletions lua/blink/cmp/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local M = {}
local download = require('blink.cmp.fuzzy.download')

M.check = function()
vim.health.start('blink.cmp healthcheck')

local required_executables = { 'curl', 'git' }
for _, executable in ipairs(required_executables) do
if vim.fn.executable(executable) == 0 then
vim.health.error(executable .. ' is not installed')
else
vim.health.ok(executable .. ' is installed')
end
end

-- check if os is supported
local system_triple = download.get_system_triple()
if system_triple then
vim.health.ok('Your system is supported by pre-built binaries (' .. system_triple .. ')')
else
vim.health.warn(
'Your system is not supported by pre-built binaries. You must run cargo build --release via your package manager with rust nightly. See the README for more info.'
)
end

if
vim.uv.fs_stat(download.lib_path)
or vim.uv.fs_stat(string.gsub(download.lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'))
then
vim.health.ok('blink_cmp_fuzzy lib is downloaded/built')
else
vim.health.warn('blink_cmp_fuzzy lib is not downloaded/built')
end
end
return M

0 comments on commit a12617d

Please sign in to comment.