fix caching

This commit is contained in:
Barrett Ruth 2025-10-01 20:21:11 -04:00
parent e6c09a4897
commit 7eb314b02c
7 changed files with 79 additions and 85 deletions

View file

@ -74,11 +74,8 @@ local function parse_command(args)
}
elseif #filtered_args == 3 then
return {
type = 'full_setup',
platform = first,
contest = filtered_args[2],
problem = filtered_args[3],
language = language,
type = 'error',
message = 'Setup contests with :CP <platform> <contest_id> [--{lang=<lang>,debug}]',
}
else
return { type = 'error', message = 'Too many arguments' }
@ -88,16 +85,6 @@ local function parse_command(args)
if state.get_platform() and state.get_contest_id() then
local cache = require('cp.cache')
cache.load()
local contest_data =
cache.get_contest_data(state.get_platform() or '', state.get_contest_id() or '')
if contest_data and contest_data.problems then
local problem_ids = vim.tbl_map(function(prob)
return prob.id
end, contest_data.problems)
if vim.tbl_contains(problem_ids, first) then
return { type = 'problem_switch', problem = first, language = language }
end
end
return {
type = 'error',
message = ("invalid subcommand '%s'"):format(first),
@ -149,24 +136,10 @@ function M.handle_command(opts)
if cmd.type == 'contest_setup' then
local setup = require('cp.setup')
if setup.set_platform(cmd.platform) then
setup.setup_contest(cmd.platform, cmd.contest, nil, cmd.language)
setup.setup_contest(cmd.platform, cmd.contest, cmd.language, nil)
end
return
end
if cmd.type == 'full_setup' then
local setup = require('cp.setup')
if setup.set_platform(cmd.platform) then
setup.setup_contest(cmd.platform, cmd.contest, cmd.problem, cmd.language)
end
return
end
if cmd.type == 'problem_switch' then
local setup = require('cp.setup')
setup.setup_problem(state.get_contest_id() or '', cmd.problem, cmd.language)
return
end
end
return M