Skip to content

Commit

Permalink
Split off the Lean 3 health check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Oct 16, 2023
1 parent 8117302 commit 2eb59c1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 34 deletions.
44 changes: 13 additions & 31 deletions lua/lean/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,30 @@
--- Support for `:checkhealth` for lean.nvim.
---@brief ]]

local health = {}

local Job = require('plenary.job')
local subprocess_check_output = require('lean._util').subprocess_check_output

local function check_lean_runnable()
local lean = subprocess_check_output{ command = "lean", args = { "--version" } }
vim.health.report_ok('`lean --version`')
vim.health.report_info(table.concat(lean, '\n'))
end

local function check_lean3ls_runnable()
local succeeded, lean3ls = pcall(Job.new, Job, {
command = 'lean-language-server',
args = { '--stdio' },
writer = ''
})
if succeeded then
lean3ls:sync()
vim.health.report_ok('`lean-language-server`')
else
vim.health.report_warn('`lean-language-server` not found, lean 3 support will not work')
end
vim.health.ok('`lean --version`')
vim.health.info(table.concat(lean, '\n'))
end

local function check_for_timers()
if not vim.tbl_isempty(vim.fn.timer_info()) then
vim.health.report_warn(
vim.health.warn(
'You have active timers, which can degrade infoview (CursorMoved) ' ..
'performance. See https://github.com/Julian/lean.nvim/issues/92.'
)
end
end

--- Check whether lean.nvim is healthy.
---
--- Call me via `:checkhealth lean`.
function health.check()
vim.health.report_start('lean.nvim')
check_lean_runnable()
check_lean3ls_runnable()
check_for_timers()
end

return health
return {
--- Check whether lean.nvim is healthy.
---
--- Call me via `:checkhealth lean`.
check = function()
vim.health.start('lean.nvim')
check_lean_runnable()
check_for_timers()
end
}
21 changes: 21 additions & 0 deletions lua/lean/lean3/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local Job = require('plenary.job')

return {
--- Check whether Lean 3 support is healthy.
---
--- Call me via `:checkhealth lean3`.
check = function()
vim.health.start('lean3')
local succeeded, lean3ls = pcall(Job.new, Job, {
command = 'lean-language-server',
args = { '--stdio' },
writer = ''
})
if succeeded then
lean3ls:sync()
vim.health.ok('`lean-language-server`')
else
vim.health.warn('`lean-language-server` not found, lean 3 support will not work')
end
end
}
5 changes: 3 additions & 2 deletions lua/lean/lean3.lua → lua/lean/lean3/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local a = require'plenary.async.util'

local Element = require('lean.widgets').Element
local components = require('lean.infoview.components')
local lsp = require('lean.lsp')
local util = require('lean._util')
local a = require'plenary.async.util'
local progress = require"lean.progress"
local progress = require('lean.progress')
local subprocess_check_output = util.subprocess_check_output

local lean3 = {}
Expand Down
1 change: 1 addition & 0 deletions lua/lean/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end
--- given bufnr.
function lsp.get_lean4_server(bufnr)
local lean_client
-- local clients = vim.lsp.get_clients{ name = 'leanls' }
vim.lsp.for_each_buffer_client(bufnr, function (client)
if client.name == 'leanls' then lean_client = client end
end)
Expand Down
1 change: 0 additions & 1 deletion lua/tests/checkhealth_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('checkhealth', function()
.*lean.nvim.*
.*- .*OK.* `lean ----version`
.*-.* Lean .*version .+
.*- .*OK.* `lean--language--server`
]], table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n'))
end)
end)
11 changes: 11 additions & 0 deletions lua/tests/lean3/checkhealth_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('tests.helpers')

describe('checkhealth', function()
it('passes the health check', function()
vim.api.nvim_command('silent checkhealth lean3')
assert.has_match([[
.*lean3:.*
.*- .*OK.* `lean--language--server`
]], table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n'))
end)
end)

0 comments on commit 2eb59c1

Please sign in to comment.