From 3fbbfa9423782b2e7f1160713e409a9231f579b6 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 4 Oct 2025 16:13:04 -0400 Subject: [PATCH] normalize scraper behavior --- doc/cp.nvim.txt | 13 ++++--------- lua/cp/cache.lua | 2 +- lua/cp/config.lua | 18 ------------------ lua/cp/setup.lua | 7 +------ lua/cp/ui/panel.lua | 11 ++--------- scrapers/atcoder.py | 16 ++++++++++++++-- 6 files changed, 22 insertions(+), 45 deletions(-) diff --git a/doc/cp.nvim.txt b/doc/cp.nvim.txt index 56802bf..60ceec3 100644 --- a/doc/cp.nvim.txt +++ b/doc/cp.nvim.txt @@ -129,6 +129,7 @@ Here's an example configuration with lazy.nvim: >lua { 'barrett-ruth/cp.nvim', cmd = 'CP', + build = 'uv sync', opts = { contests = { default = { @@ -152,8 +153,6 @@ Here's an example configuration with lazy.nvim: >lua run_panel = { ansi = true, diff_mode = 'vim', - next_test_key = '', - prev_test_key = '', max_output_lines = 50, }, diff = { @@ -162,7 +161,7 @@ Here's an example configuration with lazy.nvim: >lua '--word-diff-regex=.', '--no-prefix' }, }, }, - picker = 'telescope', -- 'telescope', 'fzf-lua', or nil (disabled) + picker = 'telescope', } } < @@ -228,8 +227,6 @@ is required: {diff_mode} (string, default: "none") Diff backend: "none", "vim", or "git". "none" displays plain buffers without highlighting, "vim" uses built-in diff, "git" provides character-level precision. - {next_test_key} (string, default: "") Key to navigate to next test case. - {prev_test_key} (string, default: "") Key to navigate to previous test case. {toggle_diff_key} (string, default: "") Key to cycle through diff modes. {max_output_lines} (number, default: 50) Maximum lines of test output. @@ -533,10 +530,8 @@ prevent them from being overridden: >lua ============================================================================== RUN PANEL KEYMAPS *cp-test-keys* - Navigate to next test case (configurable via - run_panel.next_test_key) - Navigate to previous test case (configurable via - run_panel.prev_test_key) + Navigate to next test case + Navigate to previous test case t Cycle through diff modes: none → git → vim q Exit run panel and restore layout Exit interactive terminal and restore layout diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index 11471db..5794edd 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -105,7 +105,7 @@ function M.set_contest_data(platform, contest_id, problems) local out = { name = prev.name, display_name = prev.display_name, - problems = vim.deepcopy(problems), + problems = problems, index_map = {}, } for i, p in ipairs(out.problems) do diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 912dd39..7ae439d 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -19,8 +19,6 @@ ---@class RunPanelConfig ---@field ansi boolean Enable ANSI color parsing and highlighting ---@field diff_mode "none"|"vim"|"git" Diff backend to use ----@field next_test_key string Key to navigate to next test case ----@field prev_test_key string Key to navigate to previous test case ---@field max_output_lines number Maximum lines of test output to display ---@class DiffGitConfig @@ -90,8 +88,6 @@ M.defaults = { run_panel = { ansi = true, diff_mode = 'none', - next_test_key = '', - prev_test_key = '', max_output_lines = 50, }, diff = { @@ -196,20 +192,6 @@ function M.setup(user_config) end, "diff_mode must be 'none', 'vim', or 'git'", }, - next_test_key = { - config.run_panel.next_test_key, - function(value) - return type(value) == 'string' and value ~= '' - end, - 'next_test_key must be a non-empty string', - }, - prev_test_key = { - config.run_panel.prev_test_key, - function(value) - return type(value) == 'string' and value ~= '' - end, - 'prev_test_key must be a non-empty string', - }, max_output_lines = { config.run_panel.max_output_lines, function(value) diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index 98fe0a3..4c6d03f 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -18,12 +18,7 @@ function M.set_platform(platform) return false end - if state.get_platform() == platform then - logger.log(('platform already set to %s'):format(platform)) - else - state.set_platform(platform) - logger.log(('platform set to %s'):format(platform)) - end + state.set_platform(platform) return true end diff --git a/lua/cp/ui/panel.lua b/lua/cp/ui/panel.lua index 1c6e414..7968e41 100644 --- a/lua/cp/ui/panel.lua +++ b/lua/cp/ui/panel.lua @@ -273,21 +273,14 @@ function M.toggle_run_panel(is_debug) config.run_panel.diff_mode = modes[(current_idx % #modes) + 1] refresh_run_panel() end, { buffer = buf, silent = true }) - vim.keymap.set('n', config.run_panel.next_test_key, function() + vim.keymap.set('n', '', function() navigate_test_case(1) end, { buffer = buf, silent = true }) - vim.keymap.set('n', config.run_panel.prev_test_key, function() + vim.keymap.set('n', '', function() navigate_test_case(-1) end, { buffer = buf, silent = true }) end - vim.keymap.set('n', config.run_panel.next_test_key, function() - navigate_test_case(1) - end, { buffer = test_buffers.tab_buf, silent = true }) - vim.keymap.set('n', config.run_panel.prev_test_key, function() - navigate_test_case(-1) - end, { buffer = test_buffers.tab_buf, silent = true }) - setup_keybindings_for_buffer(test_buffers.tab_buf) local execute = require('cp.runner.execute') diff --git a/scrapers/atcoder.py b/scrapers/atcoder.py index 2aab23c..0dc9dce 100644 --- a/scrapers/atcoder.py +++ b/scrapers/atcoder.py @@ -265,14 +265,26 @@ class AtcoderScraper(BaseScraper): async def scrape_contest_metadata(self, contest_id: str) -> MetadataResult: async def impl(cid: str) -> MetadataResult: - rows = await asyncio.to_thread(_scrape_tasks_sync, cid) + try: + rows = await asyncio.to_thread(_scrape_tasks_sync, cid) + except requests.HTTPError as e: + if e.response is not None and e.response.status_code == 404: + return self._create_metadata_error( + f"No problems found for contest {cid}", cid + ) + raise + problems = _to_problem_summaries(rows) if not problems: return self._create_metadata_error( f"No problems found for contest {cid}", cid ) + return MetadataResult( - success=True, error="", contest_id=cid, problems=problems + success=True, + error="", + contest_id=cid, + problems=problems, ) return await self._safe_execute("metadata", impl, contest_id)