From d862df9104ecba9df0dc844bda5cec361f3ae55c Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Wed, 24 Sep 2025 19:47:00 -0400 Subject: [PATCH] fix: only display configured platforms in pickers --- lua/cp/pickers/init.lua | 31 +++++++++++++++---------------- lua/cp/setup.lua | 2 +- lua/cp/ui/panel.lua | 19 +++++-------------- scrapers/__init__.py | 1 - 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/lua/cp/pickers/init.lua b/lua/cp/pickers/init.lua index 77c0685..096edfa 100644 --- a/lua/cp/pickers/init.lua +++ b/lua/cp/pickers/init.lua @@ -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 diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index 48ebed8..21dba2c 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -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() diff --git a/lua/cp/ui/panel.lua b/lua/cp/ui/panel.lua index 9fe2a9f..c851a04 100644 --- a/lua/cp/ui/panel.lua +++ b/lua/cp/ui/panel.lua @@ -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 diff --git a/scrapers/__init__.py b/scrapers/__init__.py index 6140dce..01e594c 100644 --- a/scrapers/__init__.py +++ b/scrapers/__init__.py @@ -1,4 +1,3 @@ -# Lazy imports to avoid module loading conflicts when running scrapers with -m def __getattr__(name): if name == "AtCoderScraper": from .atcoder import AtCoderScraper