From 540364926da771a68a1be04e2426e173027be52e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 23 Sep 2025 16:14:21 -0400 Subject: [PATCH] feat: improve logging --- lua/cp/log.lua | 6 ++++++ lua/cp/pickers/init.lua | 10 +++------- lua/cp/setup.lua | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lua/cp/log.lua b/lua/cp/log.lua index 9c702b4..6a05316 100644 --- a/lua/cp/log.lua +++ b/lua/cp/log.lua @@ -9,4 +9,10 @@ function M.log(msg, level, override) end end +function M.progress(msg) + vim.schedule(function() + vim.notify(('[cp.nvim]: %s'):format(msg), vim.log.levels.INFO) + end) +end + return M diff --git a/lua/cp/pickers/init.lua b/lua/cp/pickers/init.lua index 6cea2e0..947210a 100644 --- a/lua/cp/pickers/init.lua +++ b/lua/cp/pickers/init.lua @@ -42,7 +42,7 @@ 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.progress(('loading %s contests...'):format(platform_display_name)) if not utils.setup_python_env() then return {} @@ -91,7 +91,7 @@ local function get_contests_for_platform(platform) end cache.set_contest_list(platform, contests) - logger.log(('Loaded %d contests'):format(#contests), vim.log.levels.INFO) + logger.progress(('loaded %d contests'):format(#contests)) return contests end @@ -120,11 +120,7 @@ local function get_problems_for_contest(platform, contest_id) local constants = require('cp.constants') local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform - logger.log( - ('Scraping %s %s for problems...'):format(platform_display_name, contest_id), - vim.log.levels.INFO, - true - ) + logger.progress(('loading %s %s problems...'):format(platform_display_name, contest_id)) local plugin_path = utils.get_plugin_path() local cmd = { diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index 9b7afbb..4992543 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -42,7 +42,7 @@ function M.setup_contest(platform, contest_id, problem_id, language) return end - logger.log(('setting up contest %s %s'):format(platform, contest_id)) + logger.progress(('fetching contest %s %s...'):format(platform, contest_id)) scraper.scrape_contest_metadata(platform, contest_id, function(result) if not result.success then @@ -59,7 +59,7 @@ function M.setup_contest(platform, contest_id, problem_id, language) return end - logger.log(('found %d problems'):format(#problems)) + logger.progress(('found %d problems'):format(#problems)) state.set_contest_id(contest_id) local target_problem = problem_id or problems[1].id @@ -96,7 +96,7 @@ function M.setup_problem(contest_id, problem_id, language) local config = config_module.get_config() local platform = state.get_platform() or '' - logger.log(('setting up problem: %s%s'):format(contest_id, problem_id or '')) + logger.progress(('setting up problem %s%s...'):format(contest_id, problem_id or '')) local ctx = problem.create_context(platform, contest_id, problem_id, config, language) @@ -105,7 +105,7 @@ function M.setup_problem(contest_id, problem_id, language) state.set_test_cases(cached_tests) logger.log(('using cached test cases (%d)'):format(#cached_tests)) elseif vim.tbl_contains(config.scrapers, platform) then - logger.log('loading test cases...') + logger.progress('loading test cases...') scraper.scrape_problem_tests(platform, contest_id, problem_id, function(result) if result.success then @@ -171,7 +171,7 @@ function M.setup_problem(contest_id, problem_id, language) cache.set_file_state(vim.fn.expand('%:p'), platform, contest_id, problem_id, language) - logger.log(('switched to problem %s'):format(ctx.problem_name)) + logger.progress(('ready - problem %s'):format(ctx.problem_name)) end) if not ok then @@ -196,7 +196,7 @@ function M.scrape_remaining_problems(platform, contest_id, problems) return end - logger.log(('scraping %d uncached problems in background...'):format(#missing_problems)) + logger.progress(('caching %d remaining problems...'):format(#missing_problems)) for _, prob in ipairs(missing_problems) do scraper.scrape_problem_tests(platform, contest_id, prob.id, function(result)