forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhealth.lua
More file actions
162 lines (140 loc) · 4.95 KB
/
health.lua
File metadata and controls
162 lines (140 loc) · 4.95 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
local M = {}
local start = vim.health.start or vim.health.report_start
local error = vim.health.error or vim.health.report_error
local warn = vim.health.warn or vim.health.report_warn
local ok = vim.health.ok or vim.health.report_ok
--- Run a command and handle potential errors
---@param executable string
---@param command string
local function run_command(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 vim.trim(result)
else
return false
end
end
end
--- Check if a Lua library is installed
---@param lib_name string
---@return boolean
local function lualib_installed(lib_name)
local res, _ = pcall(require, lib_name)
return res
end
--- Check if a treesitter parser is available
---@param ft string
---@return boolean
local function treesitter_parser_available(ft)
local res, parser = pcall(vim.treesitter.get_parser, 0, ft)
return res and parser ~= nil
end
function M.check()
start('CopilotChat.nvim [core]')
local vim_version = vim.trim(vim.api.nvim_exec2('version', { output = true }).output)
if vim.fn.has('nvim-0.10.0') == 1 then
ok('nvim: ' .. vim_version)
else
error('nvim: unsupported, please upgrade to 0.10.0 or later. See "https://neovim.io/".')
end
local setup_called = require('CopilotChat').config ~= nil
if setup_called then
ok('setup: called')
else
error('setup: not called, required for plugin to work. See `:h CopilotChat-installation`.')
end
local testfile = os.tmpname()
local f = io.open(testfile, 'w')
local writable = false
if f then
f:write('test')
f:close()
writable = true
end
if writable then
ok('temp dir: writable (' .. testfile .. ')')
os.remove(testfile)
else
local stat = vim.loop.fs_stat(vim.fn.fnamemodify(testfile, ':h'))
local perms = stat and string.format('%o', stat.mode % 512) or 'unknown'
error('temp dir: not writable. Permissions: ' .. perms .. ' (dir: ' .. vim.fn.fnamemodify(testfile, ':h') .. ')')
end
start('CopilotChat.nvim [commands]')
local curl_version = run_command('curl', '--version')
if curl_version == false then
error('curl: missing, required for API requests. See "https://curl.se/".')
else
ok('curl: ' .. curl_version)
end
local git_version = run_command('git', '--version')
if git_version == false then
warn('git: missing, required for git-related commands. See "https://git-scm.com/".')
else
ok('git: ' .. git_version)
end
local rg_version = run_command('rg', '--version')
if rg_version == false then
warn('rg: missing, optional for improved search performance. See "https://github.com/BurntSushi/ripgrep".')
else
ok('rg: ' .. rg_version)
end
local lynx_version = run_command('lynx', '-version')
if lynx_version == false then
warn('lynx: missing, optional for improved fetching of url contents. See "https://lynx.invisible-island.net/".')
else
ok('lynx: ' .. lynx_version)
end
local gh_version = run_command('gh', '--version')
if gh_version == false then
warn('gh: missing, optional for improved GitHub authorization. See "https://cli.github.com/".')
else
ok('gh: ' .. gh_version)
end
start('CopilotChat.nvim [dependencies]')
if lualib_installed('plenary') then
ok('plenary: installed')
else
error('plenary: missing, required for http requests and async jobs. Install "nvim-lua/plenary.nvim" plugin.')
end
local has_copilot = lualib_installed('copilot')
local copilot_loaded = vim.g.loaded_copilot == 1
if has_copilot or copilot_loaded then
ok('copilot: ' .. (has_copilot and 'copilot.lua' or 'copilot.vim'))
else
warn(
'copilot: missing, optional for improved Copilot authorization. Install "github/copilot.vim" or "zbirenbaum/copilot.lua" plugins.'
)
end
local select_source = debug.getinfo(vim.ui.select).source
if select_source:match('vim/ui%.lua$') then
warn(
'vim.ui.select: using default implementation, which may not provide the best user experience. See `:h CopilotChat-integration-with-pickers`.'
)
else
ok('vim.ui.select: overridden by `' .. select_source .. '`')
end
if lualib_installed('tiktoken_core') then
ok('tiktoken_core: installed')
else
warn('tiktoken_core: missing, optional for accurate token counting. See README for installation instructions.')
end
if treesitter_parser_available('markdown') then
ok('treesitter[markdown]: installed')
else
warn(
'treesitter[markdown]: missing, optional for better chat highlighting. Install `nvim-treesitter/nvim-treesitter` plugin and run `:TSInstall markdown`.'
)
end
if treesitter_parser_available('diff') then
ok('treesitter[diff]: installed')
else
warn(
'treesitter[diff]: missing, optional for better diff highlighting. Install `nvim-treesitter/nvim-treesitter` plugin and run `:TSInstall diff`.'
)
end
end
return M