fix(health): simplify health check
This commit is contained in:
parent
02019dbdef
commit
dc4326524c
7 changed files with 14 additions and 53 deletions
|
|
@ -34,20 +34,6 @@ local function check_python_env()
|
|||
end
|
||||
end
|
||||
|
||||
local function check_scrapers()
|
||||
local plugin_path = utils.get_plugin_path()
|
||||
|
||||
local scrapers = { 'atcoder.py', 'codeforces.py', 'cses.py' }
|
||||
for _, scraper in ipairs(scrapers) do
|
||||
local scraper_path = plugin_path .. '/scrapers/' .. scraper
|
||||
if vim.fn.filereadable(scraper_path) == 1 then
|
||||
vim.health.ok('Scraper found: ' .. scraper)
|
||||
else
|
||||
vim.health.error('Missing scraper: ' .. scraper)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function check_luasnip()
|
||||
local has_luasnip, luasnip = pcall(require, 'luasnip')
|
||||
if has_luasnip then
|
||||
|
|
@ -59,25 +45,6 @@ local function check_luasnip()
|
|||
end
|
||||
end
|
||||
|
||||
local function check_config()
|
||||
vim.health.ok('Plugin ready')
|
||||
|
||||
local cp = require('cp')
|
||||
local context = cp.get_current_context()
|
||||
if context.platform then
|
||||
local info = context.platform
|
||||
if context.contest_id then
|
||||
info = info .. ' ' .. context.contest_id
|
||||
if context.problem_id then
|
||||
info = info .. ' ' .. context.problem_id
|
||||
end
|
||||
end
|
||||
vim.health.info('Current context: ' .. info)
|
||||
else
|
||||
vim.health.info('No contest context set')
|
||||
end
|
||||
end
|
||||
|
||||
function M.check()
|
||||
local version = require('cp.version')
|
||||
vim.health.start('cp.nvim health check')
|
||||
|
|
@ -87,9 +54,7 @@ function M.check()
|
|||
check_nvim_version()
|
||||
check_uv()
|
||||
check_python_env()
|
||||
check_scrapers()
|
||||
check_luasnip()
|
||||
check_config()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -31,14 +31,6 @@ function M.setup(opts)
|
|||
end
|
||||
end
|
||||
|
||||
function M.get_current_context()
|
||||
return {
|
||||
platform = state.get_platform(),
|
||||
contest_id = state.get_contest_id(),
|
||||
problem_id = state.get_problem_id(),
|
||||
}
|
||||
end
|
||||
|
||||
function M.is_initialized()
|
||||
return true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ end
|
|||
|
||||
function M.setup_contest(platform, contest_id, problem_id, language)
|
||||
if not state.get_platform() then
|
||||
logger.log('no platform set', vim.log.levels.ERROR)
|
||||
logger.log('No platform configured. Use :CP <platform> <contest> [...] first.')
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -215,7 +216,10 @@ function M.navigate_problem(direction, language)
|
|||
local current_problem_id = state.get_problem_id()
|
||||
|
||||
if not platform or not contest_id or not current_problem_id then
|
||||
logger.log('no contest context', vim.log.levels.ERROR)
|
||||
logger.log(
|
||||
'No platform configured. Use :CP <platform> <contest> [...] first.',
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function M.toggle_interactive()
|
|||
|
||||
if not platform then
|
||||
logger.log(
|
||||
'No platform %s configured. Use :CP <platform> <contest> [...] first.',
|
||||
'No platform configured. Use :CP <platform> <contest> [...] first.',
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
|
|
@ -131,7 +131,7 @@ function M.toggle_run_panel(is_debug)
|
|||
|
||||
if not platform then
|
||||
logger.log(
|
||||
'No platform %s configured. Use :CP <platform> <contest> [...] first.',
|
||||
'No platform configured. Use :CP <platform> <contest> [...] first.',
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ end, {
|
|||
|
||||
if num_args == 2 then
|
||||
local candidates = {}
|
||||
local cp = require('cp')
|
||||
local context = cp.get_current_context()
|
||||
if context.platform and context.contest_id then
|
||||
local state = require('cp.state')
|
||||
local platform, contest_id = state.get_platform(), state.get_contest_id()
|
||||
if platform and contest_id then
|
||||
vim.list_extend(candidates, actions)
|
||||
local cache = require('cp.cache')
|
||||
cache.load()
|
||||
local contest_data = cache.get_contest_data(context.platform, context.contest_id)
|
||||
local contest_data = cache.get_contest_data(platform, contest_id)
|
||||
if contest_data and contest_data.problems then
|
||||
for _, problem in ipairs(contest_data.problems) do
|
||||
table.insert(candidates, problem.id)
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ describe('cp command parsing', function()
|
|||
package.loaded['cp.cache'] = nil
|
||||
end)
|
||||
|
||||
it('completes platforms and global actions when no contest context', function()
|
||||
it('completes platforms and global actions without contest configuration', function()
|
||||
local result = complete_fn('', 'CP ', 3)
|
||||
|
||||
assert.is_table(result)
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ describe('Error boundary handling', function()
|
|||
has_validation_error = true
|
||||
elseif
|
||||
log_entry.msg
|
||||
and (log_entry.msg:match('no contest set') or log_entry.msg:match('No contest configured'))
|
||||
and (log_entry.msg:match('No platform ') or log_entry.msg:match('No contest '))
|
||||
then
|
||||
has_appropriate_errors = has_appropriate_errors + 1
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue