feat(cses): integrate metadata command format in lua

This commit is contained in:
Barrett Ruth 2025-09-20 14:05:40 -04:00
parent 8e13b8c61d
commit 35545a1ad2
4 changed files with 19 additions and 54 deletions

View file

@ -700,12 +700,11 @@ local function parse_command(args)
}
elseif #filtered_args == 2 then
if first == 'cses' then
return {
type = 'cses_problem',
platform = first,
problem = filtered_args[2],
language = language,
}
logger.log(
'CSES requires both category and problem ID. Usage: :CP cses <category> <problem_id>',
vim.log.levels.ERROR
)
return { type = 'error' }
else
return {
type = 'contest_setup',
@ -851,22 +850,6 @@ function M.handle_command(opts)
return
end
if cmd.type == 'cses_problem' then
if set_platform(cmd.platform) then
if vim.tbl_contains(config.scrapers, cmd.platform) then
local metadata_result = scrape.scrape_contest_metadata(cmd.platform, '')
if not metadata_result.success then
logger.log(
'failed to load contest metadata: ' .. (metadata_result.error or 'unknown error'),
vim.log.levels.WARN
)
end
end
setup_problem(cmd.problem, nil, cmd.language)
end
return
end
if cmd.type == 'problem_switch' then
if state.platform == 'cses' then
setup_problem(cmd.problem, nil, cmd.language)

View file

@ -89,29 +89,16 @@ function M.scrape_contest_metadata(platform, contest_id)
local plugin_path = get_plugin_path()
local args
if platform == 'cses' then
args = {
'uv',
'run',
'--directory',
plugin_path,
'-m',
'scrapers.' .. platform,
'metadata',
}
else
args = {
'uv',
'run',
'--directory',
plugin_path,
'-m',
'scrapers.' .. platform,
'metadata',
contest_id,
}
end
local args = {
'uv',
'run',
'--directory',
plugin_path,
'-m',
'scrapers.' .. platform,
'metadata',
contest_id,
}
local result = vim
.system(args, {
@ -140,12 +127,7 @@ function M.scrape_contest_metadata(platform, contest_id)
return data
end
local problems_list
if platform == 'cses' then
problems_list = data.categories and data.categories['CSES Problem Set'] or {}
else
problems_list = data.problems or {}
end
local problems_list = data.problems or {}
cache.set_contest_data(platform, contest_id, problems_list)
return {