rename and simplify things

This commit is contained in:
Barrett Ruth 2025-10-05 11:59:24 -04:00
parent 794426402a
commit b68ecbbe96
16 changed files with 43 additions and 297 deletions

View file

@ -16,8 +16,8 @@ local function create_none_diff_layout(parent_win, expected_content, actual_cont
local expected_win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(expected_win, expected_buf)
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = expected_buf })
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = actual_buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = expected_buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = actual_buf })
vim.api.nvim_set_option_value('winbar', 'Expected', { win = expected_win })
vim.api.nvim_set_option_value('winbar', 'Actual', { win = actual_win })
@ -53,8 +53,8 @@ local function create_vim_diff_layout(parent_win, expected_content, actual_conte
local expected_win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(expected_win, expected_buf)
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = expected_buf })
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = actual_buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = expected_buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = actual_buf })
vim.api.nvim_set_option_value('winbar', 'Expected', { win = expected_win })
vim.api.nvim_set_option_value('winbar', 'Actual', { win = actual_win })
@ -96,7 +96,7 @@ local function create_git_diff_layout(parent_win, expected_content, actual_conte
local diff_win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(diff_win, diff_buf)
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = diff_buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = diff_buf })
vim.api.nvim_set_option_value('winbar', 'Expected vs Actual', { win = diff_win })
local diff_backend = require('cp.ui.diff')
@ -132,7 +132,7 @@ local function create_single_layout(parent_win, content)
vim.cmd('resize ' .. math.floor(vim.o.lines * 0.35))
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = buf })
return {
buffers = { buf },

View file

@ -1,5 +1,8 @@
local M = {}
---@class RunOpts
---@field debug? boolean
local config_module = require('cp.config')
local layouts = require('cp.ui.layouts')
local logger = require('cp.log')
@ -51,19 +54,13 @@ function M.toggle_interactive()
local platform, contest_id = state.get_platform(), state.get_contest_id()
if not platform then
logger.log(
'No platform configured. Use :CP <platform> <contest> [--{lang=<lang>,debug}] first.',
vim.log.levels.ERROR
)
logger.log('No platform configured.', vim.log.levels.ERROR)
return
end
if not contest_id then
logger.log(
('No contest %s configured for platform %s. Use :CP <platform> <contest> [--{lang=<lang>,debug}] to set up first.'):format(
contest_id,
platform
),
('No contest %s configured for platform %s.'):format(contest_id, platform),
vim.log.levels.ERROR
)
return
@ -118,8 +115,8 @@ function M.toggle_interactive()
state.set_active_panel('interactive')
end
---@param debug? boolean
function M.toggle_run_panel(debug)
---@param run_opts? RunOpts
function M.toggle_run_panel(run_opts)
if state.get_active_panel() == 'run' then
if current_diff_layout then
current_diff_layout.cleanup()
@ -152,10 +149,7 @@ function M.toggle_run_panel(debug)
if not contest_id then
logger.log(
('No contest %s configured for platform %s. Use :CP <platform> <contest> [--{lang=<lang>,debug}] to set up first.'):format(
contest_id,
platform
),
('No contest %s configured for platform %s.'):format(contest_id, platform),
vim.log.levels.ERROR
)
return
@ -187,13 +181,6 @@ function M.toggle_run_panel(debug)
)
local config = config_module.get_config()
if config.hooks and config.hooks.before_run then
config.hooks.before_run(state)
end
if debug and config.hooks and config.hooks.before_debug then
config.hooks.before_debug(state)
end
local run = require('cp.runner.run')
local input_file = state.get_input_file()
logger.log(('run panel: checking test cases for %s'):format(input_file or 'none'))
@ -210,7 +197,7 @@ function M.toggle_run_panel(debug)
local tab_buf = utils.create_buffer_with_options()
local main_win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(main_win, tab_buf)
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = tab_buf })
vim.api.nvim_set_option_value('filetype', 'cp', { buf = tab_buf })
local test_windows = { tab_win = main_win }
local test_buffers = { tab_buf = tab_buf }
@ -282,6 +269,13 @@ function M.toggle_run_panel(debug)
setup_keybindings_for_buffer(test_buffers.tab_buf)
if config.hooks and config.hooks.before_run then
config.hooks.before_run(state)
end
if run_opts.debug and config.hooks and config.hooks.before_debug then
config.hooks.before_debug(state)
end
local execute = require('cp.runner.execute')
local compile_result = execute.compile_problem()
if compile_result.success then