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
|
|
@ -16,7 +16,7 @@ local function syshandle(result)
|
|||
end
|
||||
|
||||
local msg = 'Failed to parse scraper output: ' .. tostring(data)
|
||||
logger.log(msg, vim.log.levels.ERROR)
|
||||
logger.log(msg, { level = vim.log.levels.ERROR })
|
||||
return { success = false, error = msg }
|
||||
end
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ end
|
|||
local function run_scraper(platform, subcommand, args, opts)
|
||||
if not utils.setup_python_env() then
|
||||
local msg = 'no Python environment available (install uv or nix)'
|
||||
logger.log(msg, vim.log.levels.ERROR)
|
||||
logger.log(msg, { level = vim.log.levels.ERROR })
|
||||
if opts and opts.on_exit then
|
||||
opts.on_exit({ success = false, error = msg })
|
||||
end
|
||||
|
|
@ -125,7 +125,7 @@ local function run_scraper(platform, subcommand, args, opts)
|
|||
if stdin_pipe and not stdin_pipe:is_closing() then
|
||||
stdin_pipe:close()
|
||||
end
|
||||
logger.log('Failed to start scraper process', vim.log.levels.ERROR)
|
||||
logger.log('Failed to start scraper process', { level = vim.log.levels.ERROR })
|
||||
return { success = false, error = 'spawn failed' }
|
||||
end
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ function M.scrape_contest_metadata(platform, contest_id, callback)
|
|||
constants.PLATFORM_DISPLAY_NAMES[platform],
|
||||
contest_id
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
return
|
||||
end
|
||||
|
|
@ -232,7 +232,7 @@ function M.scrape_contest_metadata(platform, contest_id, callback)
|
|||
constants.PLATFORM_DISPLAY_NAMES[platform],
|
||||
contest_id
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
return
|
||||
end
|
||||
|
|
@ -251,7 +251,7 @@ function M.scrape_contest_list(platform)
|
|||
platform,
|
||||
(result and result.error) or 'unknown'
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
return {}
|
||||
end
|
||||
|
|
@ -261,9 +261,15 @@ end
|
|||
---@param platform string
|
||||
---@param contest_id string
|
||||
---@param callback fun(data: table)|nil
|
||||
function M.scrape_all_tests(platform, contest_id, callback)
|
||||
---@param on_done fun()|nil
|
||||
function M.scrape_all_tests(platform, contest_id, callback, on_done)
|
||||
run_scraper(platform, 'tests', { contest_id }, {
|
||||
ndjson = true,
|
||||
on_exit = function()
|
||||
if type(on_done) == 'function' then
|
||||
vim.schedule(on_done)
|
||||
end
|
||||
end,
|
||||
on_event = function(ev)
|
||||
if ev.done then
|
||||
return
|
||||
|
|
@ -275,7 +281,7 @@ function M.scrape_all_tests(platform, contest_id, callback)
|
|||
contest_id,
|
||||
ev.error
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
{ level = vim.log.levels.WARN }
|
||||
)
|
||||
return
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue