diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 374ddb0..2e3a742 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -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 ', + 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) diff --git a/lua/cp/scrape.lua b/lua/cp/scrape.lua index 11a0e73..ec5376e 100644 --- a/lua/cp/scrape.lua +++ b/lua/cp/scrape.lua @@ -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 { diff --git a/spec/command_parsing_spec.lua b/spec/command_parsing_spec.lua index 15a1cd2..2d856c6 100644 --- a/spec/command_parsing_spec.lua +++ b/spec/command_parsing_spec.lua @@ -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) diff --git a/spec/scraper_spec.lua b/spec/scraper_spec.lua index d664013..ff504aa 100644 --- a/spec/scraper_spec.lua +++ b/spec/scraper_spec.lua @@ -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()