fix: systematic context guards and full panel lifecycle (#317)

## Problem

The `CONTEST_ACTIONS` list in `handle_command` was a manually maintained
parallel of `ACTIONS` that had already drifted (`pick` was incorrectly
included, breaking `:CP pick` cold). `navigate_problem` only cancelled
the `'run'` panel on `next`/`prev`, leaving interactive and stress
terminals alive and in-flight `run_io_view` callbacks unguarded.
`pick` and `cache` also appeared twice in tab-completion when a contest
was active.

## Solution

Replace `CONTEST_ACTIONS` with a `requires_context` field on
`ParsedCommand`,
set at each parse-site in `parse_command` so the semantics live with the
action definition. Expand `navigate_problem` to call `cancel_io_view()`
and
dispatch `cancel_interactive`/`stress.cancel` for all panel types,
mirroring
the contest-switch logic. Filter already-present `pick` and `cache` from
the
context-conditional completion candidates.
This commit is contained in:
Barrett Ruth 2026-03-05 18:29:41 -05:00 committed by GitHub
parent 7e7e135681
commit 6c036a7b2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 11 deletions

View file

@ -477,9 +477,15 @@ function M.navigate_problem(direction, language)
logger.log(('navigate_problem: %s -> %s'):format(current_problem_id, problems[new_index].id))
local views = require('cp.ui.views')
views.cancel_io_view()
local active_panel = state.get_active_panel()
if active_panel == 'run' then
require('cp.ui.views').disable()
views.disable()
elseif active_panel == 'interactive' then
views.cancel_interactive()
elseif active_panel == 'stress' then
require('cp.stress').cancel()
end
local lang = nil