From d43d8e4258bda31c8b9d75d37a0c622fd613d828 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 15 Sep 2025 15:30:26 -0400 Subject: [PATCH 1/4] feat: remove diff mode --- lua/cp/init.lua | 17 +---------------- plugin/cp.lua | 2 +- readme.md | 3 +++ 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 893a50f..6f49f81 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -23,16 +23,14 @@ local state = { platform = nil, contest_id = nil, problem_id = nil, - diff_mode = false, saved_layout = nil, saved_session = nil, - temp_output = nil, test_cases = nil, test_states = {}, } local platforms = { "atcoder", "codeforces", "cses" } -local actions = { "run", "debug", "diff", "next", "prev" } +local actions = { "run", "debug", "next", "prev" } local function set_platform(platform) if not vim.tbl_contains(platforms, platform) then @@ -66,19 +64,6 @@ local function setup_problem(contest_id, problem_id, language) ) end - if state.diff_mode then - vim.cmd.diffoff() - if state.saved_session then - vim.fn.delete(state.saved_session) - state.saved_session = nil - end - if state.temp_output then - vim.fn.delete(state.temp_output) - state.temp_output = nil - end - state.diff_mode = false - end - vim.cmd("silent only") state.contest_id = contest_id diff --git a/plugin/cp.lua b/plugin/cp.lua index 9e19695..ee9e817 100644 --- a/plugin/cp.lua +++ b/plugin/cp.lua @@ -4,7 +4,7 @@ end vim.g.loaded_cp = 1 local platforms = { "atcoder", "codeforces", "cses" } -local actions = { "run", "debug", "diff", "next", "prev" } +local actions = { "run", "debug", "next", "prev" } vim.api.nvim_create_user_command("CP", function(opts) local cp = require("cp") diff --git a/readme.md b/readme.md index 0cf652f..bbec5a4 100644 --- a/readme.md +++ b/readme.md @@ -62,6 +62,7 @@ follows: ## Similar Projects - [competitest.nvim](https://github.com/xeluxee/competitest.nvim) +- [assistant.nvim](https://github.com/A7Lavinraj/assistant.nvim) ## TODO @@ -70,3 +71,5 @@ follows: - test case management - USACO support - new video with functionality, notify discord members +- note that codeforces support is scuffed: https://codeforces.com/blog/entry/146423 +- codeforces: use round number & api not the contest id From 2f95423c27813d664c2fe22a3e695941a7e62864 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 15 Sep 2025 17:54:35 -0400 Subject: [PATCH 2/4] feat: deprecate initial diff --- doc/cp.txt | 12 +++-------- lua/cp/init.lua | 56 ------------------------------------------------- 2 files changed, 3 insertions(+), 65 deletions(-) diff --git a/doc/cp.txt b/doc/cp.txt index 62cc2e1..ad69836 100644 --- a/doc/cp.txt +++ b/doc/cp.txt @@ -55,9 +55,6 @@ Action Commands ~ :CP debug Compile with debug flags and run current problem. Includes sanitizers and debug symbols. -:CP diff Enter diff mode to compare actual vs expected - output. Run again to exit diff mode. - Navigation Commands ~ :CP next Navigate to next problem in current contest. @@ -241,15 +238,12 @@ Example: Setting up and solving AtCoder contest ABC324 5. If needed, debug: > :CP debug < -6. Compare output visually: > - :CP diff -< -7. Move to next problem: > +6. Move to next problem: > :CP next < This automatically sets up problem B -8. Continue solving problems with :CP next/:CP prev navigation -9. Submit solutions on AtCoder website +7. Continue solving problems with :CP next/:CP prev navigation +8. Submit solutions on AtCoder website Example: Quick setup for single Codeforces problem > :CP codeforces 1933 a " One command setup diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 6f49f81..cb39649 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -192,60 +192,6 @@ local function debug_problem() end) end -local function diff_problem() - if state.diff_mode then - vim.cmd.diffoff() - if state.saved_session then - vim.cmd(("source %s"):format(state.saved_session)) - vim.fn.delete(state.saved_session) - state.saved_session = nil - end - if state.temp_output then - vim.fn.delete(state.temp_output) - state.temp_output = nil - end - state.diff_mode = false - return - end - - local problem_id = get_current_problem() - if not problem_id then - return - end - - local ctx = problem.create_context(state.platform, state.contest_id, state.problem_id, config) - - if vim.fn.filereadable(ctx.expected_file) == 0 then - logger.log("no expected output file found", vim.log.levels.WARN) - return - end - - if vim.fn.filereadable(ctx.output_file) == 0 then - logger.log("no output file found. run the problem first", vim.log.levels.WARN) - return - end - - local output_lines = vim.fn.readfile(ctx.output_file) - local actual_output = {} - for i = 1, #output_lines do - if output_lines[i]:match("^%[code%]:") then - break - end - table.insert(actual_output, output_lines[i]) - end - - state.temp_output = vim.fn.tempname() - vim.fn.writefile(actual_output, state.temp_output) - - state.saved_session = vim.fn.tempname() - vim.cmd(("mksession! %s"):format(state.saved_session)) - - vim.cmd("silent only") - vim.cmd(("edit %s"):format(state.temp_output)) - vim.cmd.diffthis() - vim.cmd(("vertical diffsplit %s"):format(ctx.expected_file)) - state.diff_mode = true -end ---@param delta number 1 for next, -1 for prev ---@param language? string @@ -381,8 +327,6 @@ function M.handle_command(opts) run_problem() elseif cmd.action == "debug" then debug_problem() - elseif cmd.action == "diff" then - diff_problem() elseif cmd.action == "next" then navigate_problem(1, cmd.language) elseif cmd.action == "prev" then From 88374600916d94d42930156680fa5cbae86f206c Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 15 Sep 2025 17:55:37 -0400 Subject: [PATCH 3/4] feat: remove deprecated functions --- lua/cp/window.lua | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/lua/cp/window.lua b/lua/cp/window.lua index 767a6d4..3bf7e85 100644 --- a/lua/cp/window.lua +++ b/lua/cp/window.lua @@ -122,41 +122,6 @@ function M.restore_layout(state, tile_fn) end end ----@param actual_output string ----@param expected_output string ----@param input_file string -function M.setup_diff_layout(actual_output, expected_output, input_file) - vim.validate({ - actual_output = { actual_output, "string" }, - expected_output = { expected_output, "string" }, - input_file = { input_file, "string" }, - }) - - vim.cmd.diffoff() - vim.cmd("silent only") - - local output_lines = vim.split(actual_output, "\n") - local output_buf = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_lines(output_buf, 0, -1, false, output_lines) - vim.bo[output_buf].filetype = "cp" - - vim.cmd.edit() - vim.api.nvim_set_current_buf(output_buf) - M.clearcol() - vim.cmd.diffthis() - - vim.cmd.vsplit(expected_output) - vim.bo.filetype = "cp" - M.clearcol() - vim.cmd.diffthis() - - vim.cmd.wincmd("h") - vim.cmd(("botright split %s"):format(input_file)) - vim.bo.filetype = "cp" - M.clearcol() - vim.cmd(("resize %d"):format(math.floor(vim.o.lines * 0.3))) - vim.cmd.wincmd("k") -end ---@param source_buf integer ---@param input_buf integer From 887c55d6b78955bca2ae6e06a4d409033bb7e2bd Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 15 Sep 2025 17:55:44 -0400 Subject: [PATCH 4/4] feat(ci): format --- lua/cp/init.lua | 1 - lua/cp/window.lua | 1 - 2 files changed, 2 deletions(-) diff --git a/lua/cp/init.lua b/lua/cp/init.lua index cb39649..6190ae9 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -192,7 +192,6 @@ local function debug_problem() end) end - ---@param delta number 1 for next, -1 for prev ---@param language? string local function navigate_problem(delta, language) diff --git a/lua/cp/window.lua b/lua/cp/window.lua index 3bf7e85..9431a24 100644 --- a/lua/cp/window.lua +++ b/lua/cp/window.lua @@ -122,7 +122,6 @@ function M.restore_layout(state, tile_fn) end end - ---@param source_buf integer ---@param input_buf integer ---@param output_buf integer