diff --git a/lua/cp/init.lua b/lua/cp/init.lua index e5b683b..172da51 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -249,22 +249,17 @@ function M.handle_command(opts) debug_problem() elseif cmd == "diff" then diff_problem() - else - local similar_contests = vim.tbl_filter(function(contest) - return contest:find(cmd:sub(1, 3), 1, true) == 1 - end, competition_types) - - if #similar_contests > 0 then - log( - ("unknown contest type '%s'. Did you mean: %s"):format(cmd, table.concat(similar_contests, ", ")), - vim.log.levels.ERROR - ) + elseif vim.g.cp_contest and not vim.tbl_contains(competition_types, cmd) then + if (vim.g.cp_contest == "atcoder" or vim.g.cp_contest == "codeforces") and args[2] then + setup_problem(cmd, args[2]) else - log( - ("unknown contest type '%s'. Available: [%s]"):format(cmd, table.concat(competition_types, ", ")), - vim.log.levels.ERROR - ) + setup_problem(cmd) end + else + log( + ("unknown contest type '%s'. Available: [%s]"):format(cmd, table.concat(competition_types, ", ")), + vim.log.levels.ERROR + ) end end diff --git a/lua/cp/scrape.lua b/lua/cp/scrape.lua index 600c351..9ad0a86 100644 --- a/lua/cp/scrape.lua +++ b/lua/cp/scrape.lua @@ -41,6 +41,24 @@ end function M.scrape_problem(contest, problem_id, problem_letter) ensure_io_directory() + local full_problem_id = problem_id:lower() + if contest == "atcoder" or contest == "codeforces" then + if problem_letter then + full_problem_id = full_problem_id .. problem_letter:upper() + end + end + + local input_file = "io/" .. full_problem_id .. ".in" + local expected_file = "io/" .. full_problem_id .. ".expected" + + if vim.fn.filereadable(input_file) == 1 and vim.fn.filereadable(expected_file) == 1 then + return { + success = true, + problem_id = full_problem_id, + test_count = 1, + } + end + if not setup_python_env() then return { success = false,