normalize scraper behavior

This commit is contained in:
Barrett Ruth 2025-10-04 16:13:04 -04:00
parent 91c37e35e5
commit 3fbbfa9423
6 changed files with 22 additions and 45 deletions

View file

@ -129,6 +129,7 @@ Here's an example configuration with lazy.nvim: >lua
{ {
'barrett-ruth/cp.nvim', 'barrett-ruth/cp.nvim',
cmd = 'CP', cmd = 'CP',
build = 'uv sync',
opts = { opts = {
contests = { contests = {
default = { default = {
@ -152,8 +153,6 @@ Here's an example configuration with lazy.nvim: >lua
run_panel = { run_panel = {
ansi = true, ansi = true,
diff_mode = 'vim', diff_mode = 'vim',
next_test_key = '<c-n>',
prev_test_key = '<c-p>',
max_output_lines = 50, max_output_lines = 50,
}, },
diff = { diff = {
@ -162,7 +161,7 @@ Here's an example configuration with lazy.nvim: >lua
'--word-diff-regex=.', '--no-prefix' }, '--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". {diff_mode} (string, default: "none") Diff backend: "none", "vim", or "git".
"none" displays plain buffers without highlighting, "none" displays plain buffers without highlighting,
"vim" uses built-in diff, "git" provides character-level precision. "vim" uses built-in diff, "git" provides character-level precision.
{next_test_key} (string, default: "<c-n>") Key to navigate to next test case.
{prev_test_key} (string, default: "<c-p>") Key to navigate to previous test case.
{toggle_diff_key} (string, default: "<c-t>") Key to cycle through diff modes. {toggle_diff_key} (string, default: "<c-t>") Key to cycle through diff modes.
{max_output_lines} (number, default: 50) Maximum lines of test output. {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* RUN PANEL KEYMAPS *cp-test-keys*
<c-n> Navigate to next test case (configurable via <c-n> Navigate to next test case
run_panel.next_test_key) <c-p> Navigate to previous test case
<c-p> Navigate to previous test case (configurable via
run_panel.prev_test_key)
t Cycle through diff modes: none → git → vim t Cycle through diff modes: none → git → vim
q Exit run panel and restore layout q Exit run panel and restore layout
<c-q> Exit interactive terminal and restore layout <c-q> Exit interactive terminal and restore layout

View file

@ -105,7 +105,7 @@ function M.set_contest_data(platform, contest_id, problems)
local out = { local out = {
name = prev.name, name = prev.name,
display_name = prev.display_name, display_name = prev.display_name,
problems = vim.deepcopy(problems), problems = problems,
index_map = {}, index_map = {},
} }
for i, p in ipairs(out.problems) do for i, p in ipairs(out.problems) do

View file

@ -19,8 +19,6 @@
---@class RunPanelConfig ---@class RunPanelConfig
---@field ansi boolean Enable ANSI color parsing and highlighting ---@field ansi boolean Enable ANSI color parsing and highlighting
---@field diff_mode "none"|"vim"|"git" Diff backend to use ---@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 ---@field max_output_lines number Maximum lines of test output to display
---@class DiffGitConfig ---@class DiffGitConfig
@ -90,8 +88,6 @@ M.defaults = {
run_panel = { run_panel = {
ansi = true, ansi = true,
diff_mode = 'none', diff_mode = 'none',
next_test_key = '<c-n>',
prev_test_key = '<c-p>',
max_output_lines = 50, max_output_lines = 50,
}, },
diff = { diff = {
@ -196,20 +192,6 @@ function M.setup(user_config)
end, end,
"diff_mode must be 'none', 'vim', or 'git'", "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 = { max_output_lines = {
config.run_panel.max_output_lines, config.run_panel.max_output_lines,
function(value) function(value)

View file

@ -18,12 +18,7 @@ function M.set_platform(platform)
return false return false
end end
if state.get_platform() == platform then state.set_platform(platform)
logger.log(('platform already set to %s'):format(platform))
else
state.set_platform(platform)
logger.log(('platform set to %s'):format(platform))
end
return true return true
end end

View file

@ -273,21 +273,14 @@ function M.toggle_run_panel(is_debug)
config.run_panel.diff_mode = modes[(current_idx % #modes) + 1] config.run_panel.diff_mode = modes[(current_idx % #modes) + 1]
refresh_run_panel() refresh_run_panel()
end, { buffer = buf, silent = true }) end, { buffer = buf, silent = true })
vim.keymap.set('n', config.run_panel.next_test_key, function() vim.keymap.set('n', '<c-n>', function()
navigate_test_case(1) navigate_test_case(1)
end, { buffer = buf, silent = true }) end, { buffer = buf, silent = true })
vim.keymap.set('n', config.run_panel.prev_test_key, function() vim.keymap.set('n', '<c-p>', function()
navigate_test_case(-1) navigate_test_case(-1)
end, { buffer = buf, silent = true }) end, { buffer = buf, silent = true })
end 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) setup_keybindings_for_buffer(test_buffers.tab_buf)
local execute = require('cp.runner.execute') local execute = require('cp.runner.execute')

View file

@ -265,14 +265,26 @@ class AtcoderScraper(BaseScraper):
async def scrape_contest_metadata(self, contest_id: str) -> MetadataResult: async def scrape_contest_metadata(self, contest_id: str) -> MetadataResult:
async def impl(cid: 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) problems = _to_problem_summaries(rows)
if not problems: if not problems:
return self._create_metadata_error( return self._create_metadata_error(
f"No problems found for contest {cid}", cid f"No problems found for contest {cid}", cid
) )
return MetadataResult( 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) return await self._safe_execute("metadata", impl, contest_id)