Skip to content

Commit a12617d

Browse files
feat: add health.lua and basic healthchecks (#101)
1 parent b378d50 commit a12617d

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lua/blink/cmp/fuzzy/download.lua

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function download.get_lib_extension()
1010
end
1111

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

1616
--- @param callback fun(err: string | nil)
@@ -58,12 +58,15 @@ end
5858

5959
--- @param cb fun(downloaded: boolean)
6060
function download.is_downloaded(cb)
61-
vim.uv.fs_stat(lib_path, function(err)
61+
vim.uv.fs_stat(download.lib_path, function(err)
6262
if not err then
6363
cb(true)
6464
else
6565
-- If not found, check without 'lib' prefix
66-
vim.uv.fs_stat(string.gsub(lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'), function(error) cb(not error) end)
66+
vim.uv.fs_stat(
67+
string.gsub(download.lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'),
68+
function(error) cb(not error) end
69+
)
6770
end
6871
end)
6972
end
@@ -97,7 +100,7 @@ function download.from_github(tag, cb)
97100
.. system_triple
98101
.. download.get_lib_extension()
99102

100-
vim.system({ 'curl', '--create-dirs', '-Lo', lib_path, url }, {}, function(out)
103+
vim.system({ 'curl', '--create-dirs', '-Lo', download.lib_path, url }, {}, function(out)
101104
if out.code ~= 0 then cb('Failed to download pre-build binaries: ' .. out.stderr) end
102105
cb()
103106
end)

lua/blink/cmp/health.lua

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local M = {}
2+
local download = require('blink.cmp.fuzzy.download')
3+
4+
M.check = function()
5+
vim.health.start('blink.cmp healthcheck')
6+
7+
local required_executables = { 'curl', 'git' }
8+
for _, executable in ipairs(required_executables) do
9+
if vim.fn.executable(executable) == 0 then
10+
vim.health.error(executable .. ' is not installed')
11+
else
12+
vim.health.ok(executable .. ' is installed')
13+
end
14+
end
15+
16+
-- check if os is supported
17+
local system_triple = download.get_system_triple()
18+
if system_triple then
19+
vim.health.ok('Your system is supported by pre-built binaries (' .. system_triple .. ')')
20+
else
21+
vim.health.warn(
22+
'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.'
23+
)
24+
end
25+
26+
if
27+
vim.uv.fs_stat(download.lib_path)
28+
or vim.uv.fs_stat(string.gsub(download.lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'))
29+
then
30+
vim.health.ok('blink_cmp_fuzzy lib is downloaded/built')
31+
else
32+
vim.health.warn('blink_cmp_fuzzy lib is not downloaded/built')
33+
end
34+
end
35+
return M

0 commit comments

Comments
 (0)