forked from jellydn/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth.lua
More file actions
76 lines (63 loc) · 2.11 KB
/
Copy pathhealth.lua
File metadata and controls
76 lines (63 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local M = {}
local start = vim.health.start or vim.health.report_start
local warn = vim.health.warn or vim.health.report_warn
local ok = vim.health.ok or vim.health.report_ok
--- Run a command on an executable and handle potential errors
---@param executable string
---@param command string
local function run_command_on_executable(executable, command)
local is_present = vim.fn.executable(executable)
if is_present == 0 then
return false
else
local success, result = pcall(vim.fn.system, { executable, command })
if success then
return result
else
return false
end
end
end
--- Run a python command and handle potential errors
---@param command string
local function run_python_command(command)
return run_command_on_executable('python3', command)
end
-- Add health check for python3 and pynvim
function M.check()
start('CopilotChat.nvim health check')
local python_version = run_python_command('--version')
if python_version == false then
warn('Python 3 is required')
return
end
local major, minor = string.match(python_version, 'Python (%d+)%.(%d+)')
if not (major and minor and tonumber(major) >= 3 and tonumber(minor) >= 7) then
warn('Python version 3.7 or higher is required')
else
ok('Python version ' .. major .. '.' .. minor .. ' is supported')
end
-- Create a temporary Python script to check the pynvim version
local temp_file = os.tmpname() .. '.py'
local file = io.open(temp_file, 'w')
if file == nil then
warn('Failed to create temporary Python script')
return
end
file:write('import pynvim; print(pynvim.__version__)')
file:close()
-- Run the temporary Python script and capture the output
local pynvim_version = run_python_command(temp_file)
-- Trim the output
if pynvim_version ~= false then
pynvim_version = string.gsub(pynvim_version, '^%s*(.-)%s*$', '%1')
end
-- Delete the temporary Python script
os.remove(temp_file)
if pynvim_version ~= '0.5.0' then
warn('pynvim version ' .. pynvim_version .. ' is not supported')
else
ok('pynvim version ' .. pynvim_version .. ' is supported')
end
end
return M