Skip to content

Commit 90b0522

Browse files
committed
Split off the Lean 3 health check.
1 parent 8117302 commit 90b0522

File tree

6 files changed

+49
-34
lines changed

6 files changed

+49
-34
lines changed

lua/lean/health.lua

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,30 @@
22
--- Support for `:checkhealth` for lean.nvim.
33
---@brief ]]
44

5-
local health = {}
6-
7-
local Job = require('plenary.job')
85
local subprocess_check_output = require('lean._util').subprocess_check_output
96

107
local function check_lean_runnable()
118
local lean = subprocess_check_output{ command = "lean", args = { "--version" } }
12-
vim.health.report_ok('`lean --version`')
13-
vim.health.report_info(table.concat(lean, '\n'))
14-
end
15-
16-
local function check_lean3ls_runnable()
17-
local succeeded, lean3ls = pcall(Job.new, Job, {
18-
command = 'lean-language-server',
19-
args = { '--stdio' },
20-
writer = ''
21-
})
22-
if succeeded then
23-
lean3ls:sync()
24-
vim.health.report_ok('`lean-language-server`')
25-
else
26-
vim.health.report_warn('`lean-language-server` not found, lean 3 support will not work')
27-
end
9+
vim.health.ok('`lean --version`')
10+
vim.health.info(table.concat(lean, '\n'))
2811
end
2912

3013
local function check_for_timers()
3114
if not vim.tbl_isempty(vim.fn.timer_info()) then
32-
vim.health.report_warn(
15+
vim.health.warn(
3316
'You have active timers, which can degrade infoview (CursorMoved) ' ..
3417
'performance. See https://github.com/Julian/lean.nvim/issues/92.'
3518
)
3619
end
3720
end
3821

39-
--- Check whether lean.nvim is healthy.
40-
---
41-
--- Call me via `:checkhealth lean`.
42-
function health.check()
43-
vim.health.report_start('lean.nvim')
44-
check_lean_runnable()
45-
check_lean3ls_runnable()
46-
check_for_timers()
47-
end
48-
49-
return health
22+
return {
23+
--- Check whether lean.nvim is healthy.
24+
---
25+
--- Call me via `:checkhealth lean`.
26+
check = function()
27+
vim.health.start('lean.nvim')
28+
check_lean_runnable()
29+
check_for_timers()
30+
end
31+
}

lua/lean/lean3/health.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local Job = require('plenary.job')
2+
3+
return {
4+
--- Check whether Lean 3 support is healthy.
5+
---
6+
--- Call me via `:checkhealth lean3`.
7+
check = function()
8+
vim.health.start('lean3')
9+
local succeeded, lean3ls = pcall(Job.new, Job, {
10+
command = 'lean-language-server',
11+
args = { '--stdio' },
12+
writer = ''
13+
})
14+
if succeeded then
15+
lean3ls:sync()
16+
vim.health.ok('`lean-language-server`')
17+
else
18+
vim.health.warn('`lean-language-server` not found, lean 3 support will not work')
19+
end
20+
end
21+
}

lua/lean/lean3.lua renamed to lua/lean/lean3/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
local a = require'plenary.async.util'
2+
13
local Element = require('lean.widgets').Element
24
local components = require('lean.infoview.components')
35
local lsp = require('lean.lsp')
46
local util = require('lean._util')
5-
local a = require'plenary.async.util'
6-
local progress = require"lean.progress"
7+
local progress = require('lean.progress')
78
local subprocess_check_output = util.subprocess_check_output
89

910
local lean3 = {}

lua/lean/lsp.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ end
1919
--- given bufnr.
2020
function lsp.get_lean4_server(bufnr)
2121
local lean_client
22+
-- local clients = vim.lsp.get_clients{ name = 'leanls' }
2223
vim.lsp.for_each_buffer_client(bufnr, function (client)
2324
if client.name == 'leanls' then lean_client = client end
2425
end)

lua/tests/checkhealth_spec.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ describe('checkhealth', function()
77
.*lean.nvim.*
88
.*- .*OK.* `lean ----version`
99
.*-.* Lean .*version .+
10-
.*- .*OK.* `lean--language--server`
1110
]], table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n'))
1211
end)
1312
end)

lua/tests/lean3/checkhealth_spec.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require('tests.helpers')
2+
3+
describe('checkhealth', function()
4+
it('passes the health check', function()
5+
vim.api.nvim_command('silent checkhealth lean3')
6+
assert.has_match([[
7+
.*lean.nvim.*
8+
.*- .*OK.* `lean--language--server`
9+
]], table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n'))
10+
end)
11+
end)

0 commit comments

Comments
 (0)