refactor(logger): table-based LogOpts; add sync, on_done to test stream
Problem: `logger.log` positional args were hard to extend, and adding `sync` support for pre-block notifications required a clean API. Test stream completion had no user-visible signal. `setup_contest` could silently overwrite files when a user's `filename` config returned colliding paths. Solution: Replace `(msg, level, override)` with `(msg, LogOpts?)` where `LogOpts` carries `level`, `override`, and `sync`. Sync path calls `vim.notify` directly; async path uses `vim.schedule` as before. Add `on_done` callback to `scrape_all_tests`, fired via `on_exit` and surfaced as a "Loaded N tests." notification. Detect filename collisions in `proceed()` before touching the filesystem. Migrate all call sites.
This commit is contained in:
parent
127089c57f
commit
29af2df858
18 changed files with 126 additions and 117 deletions
|
|
@ -22,15 +22,15 @@ end
|
|||
|
||||
function M.start(platform, contest_id, language)
|
||||
if not platform or not vim.tbl_contains(constants.PLATFORMS, platform) then
|
||||
logger.log('Invalid platform', vim.log.levels.ERROR)
|
||||
logger.log('Invalid platform', { level = vim.log.levels.ERROR })
|
||||
return
|
||||
end
|
||||
if not contest_id or contest_id == '' then
|
||||
logger.log('Contest ID required', vim.log.levels.ERROR)
|
||||
logger.log('Contest ID required', { level = vim.log.levels.ERROR })
|
||||
return
|
||||
end
|
||||
if race_state.timer then
|
||||
logger.log('Race already active. Use :CP race stop first.', vim.log.levels.WARN)
|
||||
logger.log('Race already active. Use :CP race stop first.', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ function M.start(platform, contest_id, language)
|
|||
local start_time = cache.get_contest_start_time(platform, contest_id)
|
||||
|
||||
if not start_time then
|
||||
logger.log('Fetching contest list...', vim.log.levels.INFO, true)
|
||||
logger.log('Fetching contest list...', { level = vim.log.levels.INFO, override = true })
|
||||
local contests = scraper.scrape_contest_list(platform)
|
||||
if contests and #contests > 0 then
|
||||
cache.set_contest_summaries(platform, contests)
|
||||
|
|
@ -52,14 +52,14 @@ function M.start(platform, contest_id, language)
|
|||
constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
|
||||
contest_id
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
local remaining = start_time - os.time()
|
||||
if remaining <= 0 then
|
||||
logger.log('Contest has already started, setting up...', vim.log.levels.INFO, true)
|
||||
logger.log('Contest has already started, setting up...', { level = vim.log.levels.INFO, override = true })
|
||||
require('cp.setup').setup_contest(platform, contest_id, nil, language)
|
||||
return
|
||||
end
|
||||
|
|
@ -75,8 +75,7 @@ function M.start(platform, contest_id, language)
|
|||
contest_id,
|
||||
format_countdown(remaining)
|
||||
),
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
{ level = vim.log.levels.INFO, override = true }
|
||||
)
|
||||
|
||||
local timer = vim.uv.new_timer()
|
||||
|
|
@ -97,7 +96,7 @@ function M.start(platform, contest_id, language)
|
|||
race_state.contest_id = nil
|
||||
race_state.language = nil
|
||||
race_state.start_time = nil
|
||||
logger.log('Contest started!', vim.log.levels.INFO, true)
|
||||
logger.log('Contest started!', { level = vim.log.levels.INFO, override = true })
|
||||
require('cp.setup').setup_contest(p, c, nil, l)
|
||||
else
|
||||
vim.notify(
|
||||
|
|
@ -116,7 +115,7 @@ end
|
|||
function M.stop()
|
||||
local timer = race_state.timer
|
||||
if not timer then
|
||||
logger.log('No active race', vim.log.levels.WARN)
|
||||
logger.log('No active race', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
timer:stop()
|
||||
|
|
@ -126,7 +125,7 @@ function M.stop()
|
|||
race_state.contest_id = nil
|
||||
race_state.language = nil
|
||||
race_state.start_time = nil
|
||||
logger.log('Race cancelled', vim.log.levels.INFO, true)
|
||||
logger.log('Race cancelled', { level = vim.log.levels.INFO, override = true })
|
||||
end
|
||||
|
||||
function M.status()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue