feat(cses): integrate metadata command format in lua
This commit is contained in:
parent
8e13b8c61d
commit
35545a1ad2
4 changed files with 19 additions and 54 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ describe('cp command parsing', function()
|
|||
end)
|
||||
|
||||
it('handles cses problem command', function()
|
||||
local opts = { fargs = { 'cses', '1234' } }
|
||||
local opts = { fargs = { 'cses', 'sorting_and_searching', '1234' } }
|
||||
|
||||
assert.has_no_errors(function()
|
||||
cp.handle_command(opts)
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ describe('cp.scrape', function()
|
|||
end)
|
||||
|
||||
it('constructs correct command for cses metadata', function()
|
||||
scrape.scrape_contest_metadata('cses', 'problemset')
|
||||
scrape.scrape_contest_metadata('cses', 'sorting_and_searching')
|
||||
|
||||
local metadata_call = nil
|
||||
for _, call in ipairs(mock_system_calls) do
|
||||
|
|
@ -227,7 +227,7 @@ describe('cp.scrape', function()
|
|||
assert.is_not_nil(metadata_call)
|
||||
assert.equals('uv', metadata_call.cmd[1])
|
||||
assert.is_true(vim.tbl_contains(metadata_call.cmd, 'metadata'))
|
||||
assert.is_false(vim.tbl_contains(metadata_call.cmd, 'problemset'))
|
||||
assert.is_true(vim.tbl_contains(metadata_call.cmd, 'sorting_and_searching'))
|
||||
end)
|
||||
|
||||
it('handles subprocess execution failure', function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue