fix: only display configured platforms in pickers

This commit is contained in:
Barrett Ruth 2025-09-24 19:47:00 -04:00
parent 177c172205
commit d862df9104
4 changed files with 21 additions and 32 deletions

View file

@ -1,6 +1,7 @@
local M = {}
local cache = require('cp.cache')
local config = require('cp.config').get_config()
local logger = require('cp.log')
local utils = require('cp.utils')
@ -18,26 +19,28 @@ local utils = require('cp.utils')
---@field name string Problem name (e.g. "Two Permutations", "Painting Walls")
---@field display_name string Formatted display name for picker
---Get list of available competitive programming platforms
---@return cp.PlatformItem[]
local function get_platforms()
local constants = require('cp.constants')
return vim.tbl_map(function(platform)
return {
id = platform,
display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
}
end, constants.PLATFORMS)
local result = {}
for _, platform in ipairs(constants.PLATFORMS) do
if config.contests[platform] then
table.insert(result, {
id = platform,
display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
})
end
end
return result
end
---Get list of contests for a specific platform
---@param platform string Platform identifier (e.g. "codeforces", "atcoder")
---@return cp.ContestItem[]
local function get_contests_for_platform(platform)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
logger.log(('loading %s contests...'):format(platform_display_name), vim.log.levels.INFO, true)
logger.log('loading contests...', vim.log.levels.INFO, true)
cache.load()
local cached_contests = cache.get_contest_list(platform)
@ -131,11 +134,7 @@ local function get_problems_for_contest(platform, contest_id)
return problems
end
logger.log(
('loading %s %s problems...'):format(platform_display_name, contest_id),
vim.log.levels.INFO,
true
)
logger.log('loading contest problems...', vim.log.levels.INFO, true)
if not utils.setup_python_env() then
return problems

View file

@ -136,7 +136,7 @@ function M.setup_problem(contest_id, problem_id, language)
local source_file = state.get_source_file(language)
if not source_file then
error('Failed to generate source file path')
return
end
vim.cmd.e(source_file)
local source_buf = vim.api.nvim_get_current_buf()

View file

@ -9,10 +9,6 @@ local state = require('cp.state')
local current_diff_layout = nil
local current_mode = nil
local function get_current_problem()
return state.get_problem_id()
end
function M.toggle_run_panel(is_debug)
if state.is_run_panel_active() then
if current_diff_layout then
@ -39,7 +35,7 @@ function M.toggle_run_panel(is_debug)
return
end
local problem_id = get_current_problem()
local problem_id = state.get_problem_id()
if not problem_id then
return
end
@ -49,9 +45,9 @@ function M.toggle_run_panel(is_debug)
logger.log(
('run panel: platform=%s, contest=%s, problem=%s'):format(
platform or 'nil',
contest_id or 'nil',
problem_id or 'nil'
tostring(platform),
tostring(contest_id),
tostring(problem_id)
)
)
@ -124,12 +120,7 @@ function M.toggle_run_panel(is_debug)
return
end
test_state.current_index = test_state.current_index + delta
if test_state.current_index < 1 then
test_state.current_index = #test_state.test_cases
elseif test_state.current_index > #test_state.test_cases then
test_state.current_index = 1
end
test_state.current_index = (test_state.current_index + delta) % #test_state.test_cases
refresh_run_panel()
end