diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 59f409d..548bdc9 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -87,11 +87,11 @@ function M.setup(user_config) return config end -local function default_filename(contest, problem_id, problem_letter) - local full_problem_id = problem_id:lower() +local function default_filename(contest, contest_id, problem_id) + local full_problem_id = contest_id:lower() if contest == "atcoder" or contest == "codeforces" then - if problem_letter then - full_problem_id = full_problem_id .. problem_letter:lower() + if problem_id then + full_problem_id = full_problem_id .. problem_id:lower() end end return full_problem_id .. ".cc" diff --git a/lua/cp/init.lua b/lua/cp/init.lua index eae2965..5dc988b 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -31,7 +31,7 @@ local function setup_contest(contest_type) logger.log(("set up %s contest environment"):format(contest_type)) end -local function setup_problem(problem_id, problem_letter) +local function setup_problem(contest_id, problem_id) if not vim.g.cp_contest then logger.log("no contest mode set. run :CP first", vim.log.levels.ERROR) return @@ -52,7 +52,10 @@ local function setup_problem(problem_id, problem_letter) vim.cmd("silent only") - local ctx = problem.create_context(vim.g.cp_contest, problem_id, problem_letter, config) + vim.g.cp_contest_id = contest_id + vim.g.cp_problem_id = problem_id + + local ctx = problem.create_context(vim.g.cp_contest, contest_id, problem_id, config) local scrape_result = scrape.scrape_problem(ctx) @@ -128,7 +131,7 @@ local function run_problem() local contest_config = config.contests[vim.g.cp_contest] vim.schedule(function() - local ctx = problem.create_context(vim.g.cp_contest, problem_id, nil, config) + local ctx = problem.create_context(vim.g.cp_contest, vim.g.cp_contest_id, vim.g.cp_problem_id, config) execute.run_problem(ctx, contest_config, false) vim.cmd.checktime() end) @@ -152,7 +155,7 @@ local function debug_problem() local contest_config = config.contests[vim.g.cp_contest] vim.schedule(function() - local ctx = problem.create_context(vim.g.cp_contest, problem_id, nil, config) + local ctx = problem.create_context(vim.g.cp_contest, vim.g.cp_contest_id, vim.g.cp_problem_id, config) execute.run_problem(ctx, contest_config, true) vim.cmd.checktime() end) @@ -171,7 +174,7 @@ local function diff_problem() return end - local ctx = problem.create_context(vim.g.cp_contest, problem_id, nil, config) + local ctx = problem.create_context(vim.g.cp_contest, vim.g.cp_contest_id, vim.g.cp_problem_id, config) if vim.fn.filereadable(ctx.expected_file) == 0 then logger.log(("No expected output file found: %s"):format(ctx.expected_file), vim.log.levels.ERROR) diff --git a/lua/cp/problem.lua b/lua/cp/problem.lua index bc41175..2ae83a7 100644 --- a/lua/cp/problem.lua +++ b/lua/cp/problem.lua @@ -1,7 +1,7 @@ ---@class ProblemContext ---@field contest string Contest name (e.g. "atcoder", "codeforces") ----@field problem_id string Raw problem ID (e.g. "abc123", "1933") ----@field problem_letter? string Problem letter for AtCoder/Codeforces (e.g. "a", "b") +---@field contest_id string Contest ID (e.g. "abc123", "1933") +---@field problem_id? string Problem ID for AtCoder/Codeforces (e.g. "a", "b") ---@field source_file string Source filename (e.g. "abc123a.cpp") ---@field binary_file string Binary output path (e.g. "build/abc123a") ---@field input_file string Input test file path (e.g. "io/abc123a.in") @@ -12,19 +12,19 @@ local M = {} ---@param contest string ----@param problem_id string ----@param problem_letter? string +---@param contest_id string +---@param problem_id? string ---@param config cp.Config ---@return ProblemContext -function M.create_context(contest, problem_id, problem_letter, config) +function M.create_context(contest, contest_id, problem_id, config) local filename_fn = config.filename or require("cp.config").default_filename - local source_file = filename_fn(contest, problem_id, problem_letter) + local source_file = filename_fn(contest, contest_id, problem_id) local base_name = vim.fn.fnamemodify(source_file, ":t:r") return { contest = contest, + contest_id = contest_id, problem_id = problem_id, - problem_letter = problem_letter, source_file = source_file, binary_file = ("build/%s"):format(base_name), input_file = ("io/%s.in"):format(base_name), diff --git a/lua/cp/scrape.lua b/lua/cp/scrape.lua index 8bf1fdc..b03a5c1 100644 --- a/lua/cp/scrape.lua +++ b/lua/cp/scrape.lua @@ -59,9 +59,9 @@ function M.scrape_problem(ctx) local args if ctx.contest == "cses" then - args = { "uv", "run", scraper_path, ctx.problem_id } + args = { "uv", "run", scraper_path, ctx.contest_id } else - args = { "uv", "run", scraper_path, ctx.problem_id, ctx.problem_letter } + args = { "uv", "run", scraper_path, ctx.contest_id, ctx.problem_id } end local result = vim.system(args, {