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 M = {}
local cache = require('cp.cache') local cache = require('cp.cache')
local config = require('cp.config').get_config()
local logger = require('cp.log') local logger = require('cp.log')
local utils = require('cp.utils') 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 name string Problem name (e.g. "Two Permutations", "Painting Walls")
---@field display_name string Formatted display name for picker ---@field display_name string Formatted display name for picker
---Get list of available competitive programming platforms
---@return cp.PlatformItem[] ---@return cp.PlatformItem[]
local function get_platforms() local function get_platforms()
local constants = require('cp.constants') local constants = require('cp.constants')
return vim.tbl_map(function(platform) local result = {}
return {
for _, platform in ipairs(constants.PLATFORMS) do
if config.contests[platform] then
table.insert(result, {
id = platform, id = platform,
display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform, display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
} })
end, constants.PLATFORMS) end
end
return result
end end
---Get list of contests for a specific platform ---Get list of contests for a specific platform
---@param platform string Platform identifier (e.g. "codeforces", "atcoder") ---@param platform string Platform identifier (e.g. "codeforces", "atcoder")
---@return cp.ContestItem[] ---@return cp.ContestItem[]
local function get_contests_for_platform(platform) local function get_contests_for_platform(platform)
local constants = require('cp.constants') logger.log('loading contests...', vim.log.levels.INFO, true)
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)
cache.load() cache.load()
local cached_contests = cache.get_contest_list(platform) local cached_contests = cache.get_contest_list(platform)
@ -131,11 +134,7 @@ local function get_problems_for_contest(platform, contest_id)
return problems return problems
end end
logger.log( logger.log('loading contest problems...', vim.log.levels.INFO, true)
('loading %s %s problems...'):format(platform_display_name, contest_id),
vim.log.levels.INFO,
true
)
if not utils.setup_python_env() then if not utils.setup_python_env() then
return problems 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) local source_file = state.get_source_file(language)
if not source_file then if not source_file then
error('Failed to generate source file path') return
end end
vim.cmd.e(source_file) vim.cmd.e(source_file)
local source_buf = vim.api.nvim_get_current_buf() 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_diff_layout = nil
local current_mode = nil local current_mode = nil
local function get_current_problem()
return state.get_problem_id()
end
function M.toggle_run_panel(is_debug) function M.toggle_run_panel(is_debug)
if state.is_run_panel_active() then if state.is_run_panel_active() then
if current_diff_layout then if current_diff_layout then
@ -39,7 +35,7 @@ function M.toggle_run_panel(is_debug)
return return
end end
local problem_id = get_current_problem() local problem_id = state.get_problem_id()
if not problem_id then if not problem_id then
return return
end end
@ -49,9 +45,9 @@ function M.toggle_run_panel(is_debug)
logger.log( logger.log(
('run panel: platform=%s, contest=%s, problem=%s'):format( ('run panel: platform=%s, contest=%s, problem=%s'):format(
platform or 'nil', tostring(platform),
contest_id or 'nil', tostring(contest_id),
problem_id or 'nil' tostring(problem_id)
) )
) )
@ -124,12 +120,7 @@ function M.toggle_run_panel(is_debug)
return return
end end
test_state.current_index = test_state.current_index + delta test_state.current_index = (test_state.current_index + delta) % #test_state.test_cases
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
refresh_run_panel() refresh_run_panel()
end end

View file

@ -1,4 +1,3 @@
# Lazy imports to avoid module loading conflicts when running scrapers with -m
def __getattr__(name): def __getattr__(name):
if name == "AtCoderScraper": if name == "AtCoderScraper":
from .atcoder import AtCoderScraper from .atcoder import AtCoderScraper