fix: cleanup logs

This commit is contained in:
Barrett Ruth 2025-10-23 18:29:20 -04:00
parent c312ccbb4d
commit dc6f2fd5b6
3 changed files with 30 additions and 66 deletions

View file

@ -165,6 +165,7 @@ end
function M.setup_problem(problem_id, language) function M.setup_problem(problem_id, language)
local platform = state.get_platform() local platform = state.get_platform()
if not platform then if not platform then
logger.log('No platform/contest/problem configured.', vim.log.levels.ERROR)
return return
end end

View file

@ -70,37 +70,24 @@ function M.toggle_interactive(interactor_cmd)
return return
end end
local platform, contest_id = state.get_platform(), state.get_contest_id() local platform, contest_id, problem_id =
if not platform then state.get_platform(), state.get_contest_id(), state.get_problem_id()
logger.log('No platform configured.', vim.log.levels.ERROR) if not platform or not contest_id or not problem_id then
return
end
if not contest_id then
logger.log( logger.log(
("No contest %s configured for platform '%s'."):format( 'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
contest_id,
constants.PLATFORM_DISPLAY_NAMES[platform]
),
vim.log.levels.ERROR vim.log.levels.ERROR
) )
return return
end end
local problem_id = state.get_problem_id()
if not problem_id then
logger.log('No problem is active.', vim.log.levels.ERROR)
return
end
cache.load() cache.load()
local contest_data = cache.get_contest_data(platform, contest_id) local contest_data = cache.get_contest_data(platform, contest_id)
if if
not contest_data not contest_data
or not contest_data.index_map or not contest_data.index_map
or not contest_data.problems[contest_data.index_map[problem_id]]
or not contest_data.problems[contest_data.index_map[problem_id]].interactive or not contest_data.problems[contest_data.index_map[problem_id]].interactive
then then
logger.log('This problem is not interactive. Use :CP run.', vim.log.levels.ERROR) logger.log('This problem is not interactive. Use :CP {run,panel}.', vim.log.levels.ERROR)
return return
end end
@ -223,13 +210,13 @@ function M.toggle_interactive(interactor_cmd)
end end
function M.ensure_io_view() function M.ensure_io_view()
local platform, contest_id = state.get_platform(), state.get_contest_id() local platform, contest_id, problem_id =
if not platform or not contest_id then state.get_platform(), state.get_contest_id(), state.get_problem_id()
return if not platform or not contest_id or not problem_id then
end logger.log(
'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
local problem_id = state.get_problem_id() vim.log.levels.ERROR
if not problem_id then )
return return
end end
@ -238,9 +225,9 @@ function M.ensure_io_view()
if if
contest_data contest_data
and contest_data.index_map and contest_data.index_map
and contest_data.problems[contest_data.index_map[problem_id]]
and contest_data.problems[contest_data.index_map[problem_id]].interactive and contest_data.problems[contest_data.index_map[problem_id]].interactive
then then
logger.log('No platform configured.', vim.log.levels.ERROR)
return return
end end
@ -285,8 +272,8 @@ function M.ensure_io_view()
end end
end end
utils.update_buffer_content(input_buf, {}, nil, nil) utils.update_buffer_content(input_buf, {})
utils.update_buffer_content(output_buf, {}, nil, nil) utils.update_buffer_content(output_buf, {})
vim.api.nvim_set_current_win(solution_win) vim.api.nvim_set_current_win(solution_win)
@ -294,40 +281,23 @@ function M.ensure_io_view()
end end
function M.run_io_view(test_index) function M.run_io_view(test_index)
local platform, contest_id = state.get_platform(), state.get_contest_id() local platform, contest_id, problem_id =
if not platform then state.get_platform(), state.get_contest_id(), state.get_problem_id()
if not platform or not contest_id or not problem_id then
logger.log( logger.log(
'No platform configured. Use :CP <platform> <contest> [...] first.', 'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
vim.log.levels.ERROR vim.log.levels.ERROR
) )
return
end
if not contest_id then
logger.log(
("No contest configured for platform '%s'."):format(
constants.PLATFORM_DISPLAY_NAMES[platform]
),
vim.log.levels.ERROR
)
return
end
local problem_id = state.get_problem_id()
if not problem_id then
logger.log('No problem is active.', vim.log.levels.ERROR)
return
end end
cache.load() cache.load()
local contest_data = cache.get_contest_data(platform, contest_id) local contest_data = cache.get_contest_data(platform, contest_id)
if if
contest_data not contest_data
and contest_data.index_map or not contest_data.index_map
and contest_data.problems[contest_data.index_map[problem_id]] or not contest_data.problems[contest_data.index_map[problem_id]].interactive
and contest_data.problems[contest_data.index_map[problem_id]].interactive
then then
logger.log('This is an interactive problem. Use :CP interact instead.', vim.log.levels.WARN) logger.log('This problem is not interactive. Use :CP {run,panel}.', vim.log.levels.ERROR)
return return
end end
@ -480,20 +450,9 @@ function M.toggle_panel(panel_opts)
local platform, contest_id = state.get_platform(), state.get_contest_id() local platform, contest_id = state.get_platform(), state.get_contest_id()
if not platform then if not platform or not contest_id then
logger.log( logger.log(
'No platform configured. Use :CP <platform> <contest> [...] first.', 'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
vim.log.levels.ERROR
)
return
end
if not contest_id then
logger.log(
("No contest '%s' configured for platform '%s'."):format(
contest_id,
constants.PLATFORM_DISPLAY_NAMES[platform]
),
vim.log.levels.ERROR vim.log.levels.ERROR
) )
return return

View file

@ -125,6 +125,10 @@ function M.create_buffer_with_options(filetype)
return buf return buf
end end
---@param bufnr integer
---@param lines string[]
---@param highlights? Highlight[]
---@param namespace? integer
function M.update_buffer_content(bufnr, lines, highlights, namespace) function M.update_buffer_content(bufnr, lines, highlights, namespace)
local was_readonly = vim.api.nvim_get_option_value('readonly', { buf = bufnr }) local was_readonly = vim.api.nvim_get_option_value('readonly', { buf = bufnr })