-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathhealth.lua
More file actions
280 lines (237 loc) · 8.32 KB
/
health.lua
File metadata and controls
280 lines (237 loc) · 8.32 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
local M = {}
local health = vim.health or require('health')
local config = require('opencode.config')
local util = require('opencode.util')
local function command_exists(cmd)
return vim.fn.executable(cmd) == 1
end
local function get_opencode_version()
if not command_exists(config.opencode_executable) then
return nil, 'opencode command not found'
end
local result = vim.system({ config.opencode_executable, '--version' }):wait()
if result.code ~= 0 then
return nil, 'Failed to get opencode version: ' .. (result.stderr or 'unknown error')
end
local out = (result.stdout or ''):gsub('%s+$', '')
local version = out:match('(%d+%.%d+%.%d+)') or out
return version, nil
end
local function check_opencode_cli()
health.start('OpenCode CLI')
local state = require('opencode.state')
local required_version = state.required_version
if not command_exists(config.opencode_executable) then
health.error('opencode command not found', {
'Install opencode CLI from: https://docs.opencode.com/installation',
'Ensure opencode is in your PATH',
})
return
end
health.ok('opencode command found')
local version, err = get_opencode_version()
if not version then
health.error('Could not determine opencode version: ' .. (err or 'unknown error'))
return
end
if not util.is_version_greater_or_equal(version, required_version) then
health.error(string.format('Unsupported opencode CLI version: %s (requires >= %s)', version, required_version), {
'Update opencode CLI to the latest version',
'Visit: https://docs.opencode.com/installation',
})
return
end
health.ok(string.format('opencode CLI version: %s (>= %s required)', version, required_version))
end
local function check_opencode_server()
health.start('OpenCode Server')
local opencode_server = require('opencode.opencode_server').new()
local server = opencode_server:spawn():wait() --[[@as OpencodeServer]]
if server and server.url then
health.ok('opencode server started successfully at ' .. server.url)
else
health.error('Failed to start opencode server')
end
-- Ensure the server is really running by making a simple request
local server_job = require('opencode.server_job')
local result = server_job.call_api(server.url .. '/config', 'GET', nil):wait()
if result and result then
health.ok('opencode server is reachable')
if result['$schema'] then
health.ok('opencode server configuration available')
else
health.error('opencode server configuration not available')
end
else
health.error('opencode server did not respond as expected')
end
local shutdown_promise = server:shutdown()
shutdown_promise:wait()
if shutdown_promise:is_resolved() then
health.ok('opencode server shut down successfully')
else
health.error('Failed to shut down opencode server')
end
end
local function check_dependencies()
health.start('Dependencies')
local plenary_ok, _ = pcall(require, 'plenary.job')
if not plenary_ok then
health.error('plenary.nvim not found', {
'Install plenary.nvim: https://github.com/nvim-lua/plenary.nvim',
'Example with lazy.nvim: { "nvim-lua/plenary.nvim" }',
})
else
health.ok('plenary.nvim found')
end
end
local function check_configuration()
health.start('Configuration')
local config_ok, config = pcall(require, 'opencode.config')
if not config_ok then
health.error('Failed to load opencode configuration')
return
end
---@cast config OpencodeConfig
local valid_positions = { 'left', 'right', 'top', 'bottom', 'current' }
if not vim.tbl_contains(valid_positions, config.ui.position) then
health.warn(
string.format('Invalid UI position: %s', config.ui.position),
{ 'Valid positions: ' .. table.concat(valid_positions, ', ') }
)
else
health.ok(string.format('UI position: %s', config.ui.position))
end
if config.ui.window_width <= 0 or config.ui.window_width > 1 then
health.warn(
string.format('Invalid window width: %s', config.ui.window_width),
{ 'Window width should be between 0 and 1 (percentage of screen)' }
)
else
health.ok(string.format('Window width: %s', config.ui.window_width))
end
if config.ui.input_height <= 0 or config.ui.input_height > 1 then
health.warn(
string.format('Invalid input height: %s', config.ui.input_height),
{ 'Input height should be between 0 and 1 (percentage of screen)' }
)
else
health.ok(string.format('Input height: %s', config.ui.input_height))
end
local min_height = config.ui.input.min_height
local max_height = config.ui.input.max_height
if min_height ~= nil or max_height ~= nil then
if type(min_height) ~= 'number' or type(max_height) ~= 'number' then
health.warn(
'Input min/max height configuration incomplete',
{ 'Set both ui.input.min_height and ui.input.max_height to enable auto-resize' }
)
else
if min_height <= 0 or min_height > 1 then
health.warn(
string.format('Invalid input min height: %s', min_height),
{ 'Input min height should be between 0 and 1 (percentage of screen)' }
)
else
health.ok(string.format('Input min height: %s', min_height))
end
if max_height <= 0 or max_height > 1 then
health.warn(
string.format('Invalid input max height: %s', max_height),
{ 'Input max height should be between 0 and 1 (percentage of screen)' }
)
else
health.ok(string.format('Input max height: %s', max_height))
end
if min_height > max_height then
health.warn(
'Input min height exceeds max height',
{ 'Ensure ui.input.min_height is less than or equal to ui.input.max_height' }
)
end
end
end
health.ok('Configuration loaded successfully')
end
local function check_environment()
health.start('Environment')
local git_dir = vim.fn.system('git rev-parse --git-dir 2>/dev/null'):gsub('\n', '')
if vim.v.shell_error == 0 and git_dir ~= '' then
health.ok('Git repository detected')
else
health.info('Not in a git repository (optional but recommended for opencode)')
end
local cwd = vim.fn.getcwd()
if cwd and cwd ~= '' then
health.ok(string.format('Working directory: %s', cwd))
else
health.warn('Could not determine current working directory')
end
end
local function check_integrations()
health.start('Optional Integrations')
local telescope_ok, _ = pcall(require, 'telescope')
if telescope_ok then
health.ok('telescope.nvim found (enhanced file picker available)')
else
health.info('telescope.nvim not found (using vim.ui.select for file picker)')
end
local mini_pick_ok, _ = pcall(require, 'mini.pick')
if mini_pick_ok then
health.ok('mini.pick found (enhanced file picker available)')
else
health.info('mini.pick not found')
end
local fzf_lua_ok, _ = pcall(require, 'fzf-lua')
if fzf_lua_ok then
health.ok('fzf-lua found (enhanced file picker available)')
else
health.info('fzf-lua not found')
end
local snacks_ok, _ = pcall(require, 'snacks')
if snacks_ok then
health.ok('snacks.nvim found (enhanced file picker available)')
else
health.info('snacks.nvim not found')
end
local blink_ok, _ = pcall(require, 'blink.cmp')
if blink_ok then
health.ok('blink found (enhanced completion available)')
else
health.info('blink not found')
end
local cmp_ok, _ = pcall(require, 'cmp')
if cmp_ok then
health.ok('nvim-cmp found (enhanced completion available)')
else
health.info('nvim-cmp not found')
end
if not blink_ok and not cmp_ok then
health.warn('No completion engine found, will fallback to vim_complete (consider installing blink or nvim-cmp)')
end
end
local function check_finder_cli_tools()
health.start('Finder CLI Tools')
local find_cmds = { 'fd', 'rg', 'git' }
local found = false
for _, cmd in ipairs(find_cmds) do
if command_exists(cmd) then
health.ok(string.format('Found file finder command: %s', cmd))
found = true
break
end
end
if not found then
health.warn('No file finder command found (consider installing fd, rg, git, or find)')
end
end
function M.check()
check_opencode_cli()
check_opencode_server()
check_dependencies()
check_configuration()
check_environment()
check_integrations()
check_finder_cli_tools()
end
return M