commit
89e3c0e21d
4 changed files with 38 additions and 1 deletions
|
|
@ -194,6 +194,8 @@ function M.compile_problem(debug, on_complete)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require('cp.utils').ensure_dirs()
|
||||||
|
|
||||||
local binary = debug and state.get_debug_file() or state.get_binary_file()
|
local binary = debug and state.get_debug_file() or state.get_binary_file()
|
||||||
local substitutions = { source = state.get_source_file(), binary = binary }
|
local substitutions = { source = state.get_source_file(), binary = binary }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ function M.scrape_all_tests(platform, contest_id, callback)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.system({ 'mkdir', '-p', 'build', 'io' }):wait()
|
require('cp.utils').ensure_dirs()
|
||||||
local config = require('cp.config')
|
local config = require('cp.config')
|
||||||
local base_name = config.default_filename(contest_id, ev.problem_id)
|
local base_name = config.default_filename(contest_id, ev.problem_id)
|
||||||
for i, t in ipairs(ev.tests) do
|
for i, t in ipairs(ev.tests) do
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ local utils = require('cp.utils')
|
||||||
|
|
||||||
local current_diff_layout = nil
|
local current_diff_layout = nil
|
||||||
local current_mode = nil
|
local current_mode = nil
|
||||||
|
local io_view_running = false
|
||||||
|
|
||||||
function M.disable()
|
function M.disable()
|
||||||
local active_panel = state.get_active_panel()
|
local active_panel = state.get_active_panel()
|
||||||
|
|
@ -390,6 +391,8 @@ function M.ensure_io_view()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require('cp.utils').ensure_dirs()
|
||||||
|
|
||||||
local source_file = state.get_source_file()
|
local source_file = state.get_source_file()
|
||||||
if source_file then
|
if source_file then
|
||||||
local source_file_abs = vim.fn.fnamemodify(source_file, ':p')
|
local source_file_abs = vim.fn.fnamemodify(source_file, ':p')
|
||||||
|
|
@ -622,6 +625,12 @@ local function render_io_view_results(io_state, test_indices, mode, combined_res
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run_io_view(test_indices_arg, debug, mode)
|
function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
|
if io_view_running then
|
||||||
|
logger.log('Tests already running', vim.log.levels.WARN)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
io_view_running = true
|
||||||
|
|
||||||
logger.log(('%s tests...'):format(debug and 'Debugging' or 'Running'), vim.log.levels.INFO, true)
|
logger.log(('%s tests...'):format(debug and 'Debugging' or 'Running'), vim.log.levels.INFO, true)
|
||||||
|
|
||||||
mode = mode or 'combined'
|
mode = mode or 'combined'
|
||||||
|
|
@ -633,6 +642,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
|
'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -640,6 +650,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
local contest_data = cache.get_contest_data(platform, contest_id)
|
local contest_data = cache.get_contest_data(platform, contest_id)
|
||||||
if not contest_data or not contest_data.index_map then
|
if not contest_data or not contest_data.index_map then
|
||||||
logger.log('No test cases available.', vim.log.levels.ERROR)
|
logger.log('No test cases available.', vim.log.levels.ERROR)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -656,11 +667,13 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
local combined = cache.get_combined_test(platform, contest_id, problem_id)
|
local combined = cache.get_combined_test(platform, contest_id, problem_id)
|
||||||
if not combined then
|
if not combined then
|
||||||
logger.log('No combined test available', vim.log.levels.ERROR)
|
logger.log('No combined test available', vim.log.levels.ERROR)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if not run.load_test_cases() then
|
if not run.load_test_cases() then
|
||||||
logger.log('No test cases available', vim.log.levels.ERROR)
|
logger.log('No test cases available', vim.log.levels.ERROR)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -681,6 +694,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
),
|
),
|
||||||
vim.log.levels.WARN
|
vim.log.levels.WARN
|
||||||
)
|
)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -698,6 +712,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
|
|
||||||
local io_state = state.get_io_view_state()
|
local io_state = state.get_io_view_state()
|
||||||
if not io_state then
|
if not io_state then
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -711,6 +726,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
|
|
||||||
execute.compile_problem(debug, function(compile_result)
|
execute.compile_problem(debug, function(compile_result)
|
||||||
if not vim.api.nvim_buf_is_valid(io_state.output_buf) then
|
if not vim.api.nvim_buf_is_valid(io_state.output_buf) then
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -730,6 +746,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
|
|
||||||
local ns = vim.api.nvim_create_namespace('cp_io_view_compile_error')
|
local ns = vim.api.nvim_create_namespace('cp_io_view_compile_error')
|
||||||
utils.update_buffer_content(io_state.output_buf, lines, highlights, ns)
|
utils.update_buffer_content(io_state.output_buf, lines, highlights, ns)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -737,6 +754,7 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
local combined = cache.get_combined_test(platform, contest_id, problem_id)
|
local combined = cache.get_combined_test(platform, contest_id, problem_id)
|
||||||
if not combined then
|
if not combined then
|
||||||
logger.log('No combined test found', vim.log.levels.ERROR)
|
logger.log('No combined test found', vim.log.levels.ERROR)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -745,18 +763,21 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
run.run_combined_test(debug, function(result)
|
run.run_combined_test(debug, function(result)
|
||||||
if not result then
|
if not result then
|
||||||
logger.log('Failed to run combined test', vim.log.levels.ERROR)
|
logger.log('Failed to run combined test', vim.log.levels.ERROR)
|
||||||
|
io_view_running = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.api.nvim_buf_is_valid(io_state.output_buf) then
|
if vim.api.nvim_buf_is_valid(io_state.output_buf) then
|
||||||
render_io_view_results(io_state, test_indices, mode, result, combined.input)
|
render_io_view_results(io_state, test_indices, mode, result, combined.input)
|
||||||
end
|
end
|
||||||
|
io_view_running = false
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
run.run_all_test_cases(test_indices, debug, nil, function()
|
run.run_all_test_cases(test_indices, debug, nil, function()
|
||||||
if vim.api.nvim_buf_is_valid(io_state.output_buf) then
|
if vim.api.nvim_buf_is_valid(io_state.output_buf) then
|
||||||
render_io_view_results(io_state, test_indices, mode, nil, nil)
|
render_io_view_results(io_state, test_indices, mode, nil, nil)
|
||||||
end
|
end
|
||||||
|
io_view_running = false
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
@ -859,6 +880,9 @@ function M.toggle_panel(panel_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function refresh_panel()
|
local function refresh_panel()
|
||||||
|
if state.get_active_panel() ~= 'run' then
|
||||||
|
return
|
||||||
|
end
|
||||||
if not test_buffers.tab_buf or not vim.api.nvim_buf_is_valid(test_buffers.tab_buf) then
|
if not test_buffers.tab_buf or not vim.api.nvim_buf_is_valid(test_buffers.tab_buf) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -884,6 +908,10 @@ function M.toggle_panel(panel_opts)
|
||||||
vim.cmd.normal({ 'zz', bang = true })
|
vim.cmd.normal({ 'zz', bang = true })
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if test_windows.tab_win and vim.api.nvim_win_is_valid(test_windows.tab_win) then
|
||||||
|
vim.api.nvim_set_current_win(test_windows.tab_win)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function navigate_test_case(delta)
|
local function navigate_test_case(delta)
|
||||||
|
|
@ -942,6 +970,9 @@ function M.toggle_panel(panel_opts)
|
||||||
|
|
||||||
local function finalize_panel()
|
local function finalize_panel()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
if state.get_active_panel() ~= 'run' then
|
||||||
|
return
|
||||||
|
end
|
||||||
if config.ui.ansi then
|
if config.ui.ansi then
|
||||||
require('cp.ui.ansi').setup_highlight_groups()
|
require('cp.ui.ansi').setup_highlight_groups()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -262,4 +262,8 @@ function M.cwd_executables()
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.ensure_dirs()
|
||||||
|
vim.system({ 'mkdir', '-p', 'build', 'io' }):wait()
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue