feat: refactor file structure

This commit is contained in:
Barrett Ruth 2025-09-21 14:29:01 -04:00
parent 9761cded88
commit 965e47a1df
17 changed files with 19 additions and 22 deletions

View file

@ -178,7 +178,6 @@ function M.setup(user_config)
local config = vim.tbl_deep_extend('force', M.defaults, user_config or {}) local config = vim.tbl_deep_extend('force', M.defaults, user_config or {})
-- Validate merged config values
vim.validate({ vim.validate({
before_run = { before_run = {
config.hooks.before_run, config.hooks.before_run,

View file

@ -246,7 +246,7 @@ local function toggle_run_panel(is_debug)
end end
local ctx = problem.create_context(state.platform, state.contest_id, state.problem_id, config) local ctx = problem.create_context(state.platform, state.contest_id, state.problem_id, config)
local run = require('cp.run') local run = require('cp.runner.run')
if not run.load_test_cases(ctx, state) then if not run.load_test_cases(ctx, state) then
logger.log('no test cases found', vim.log.levels.WARN) logger.log('no test cases found', vim.log.levels.WARN)
@ -270,7 +270,7 @@ local function toggle_run_panel(is_debug)
tab_buf = tab_buf, tab_buf = tab_buf,
} }
local highlight = require('cp.highlight') local highlight = require('cp.ui.highlight')
local diff_namespace = highlight.create_namespace() local diff_namespace = highlight.create_namespace()
local test_list_namespace = vim.api.nvim_create_namespace('cp_test_list') local test_list_namespace = vim.api.nvim_create_namespace('cp_test_list')
@ -347,7 +347,7 @@ local function toggle_run_panel(is_debug)
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = diff_buf }) vim.api.nvim_set_option_value('filetype', 'cptest', { buf = diff_buf })
vim.api.nvim_set_option_value('winbar', 'Expected vs Actual', { win = diff_win }) vim.api.nvim_set_option_value('winbar', 'Expected vs Actual', { win = diff_win })
local diff_backend = require('cp.diff') local diff_backend = require('cp.ui.diff')
local backend = diff_backend.get_best_backend('git') local backend = diff_backend.get_best_backend('git')
local diff_result = backend.render(expected_content, actual_content) local diff_result = backend.render(expected_content, actual_content)
@ -459,7 +459,7 @@ local function toggle_run_panel(is_debug)
ansi_namespace ansi_namespace
) )
elseif desired_mode == 'git' then elseif desired_mode == 'git' then
local diff_backend = require('cp.diff') local diff_backend = require('cp.ui.diff')
local backend = diff_backend.get_best_backend('git') local backend = diff_backend.get_best_backend('git')
local diff_result = backend.render(expected_content, actual_content) local diff_result = backend.render(expected_content, actual_content)
@ -513,7 +513,7 @@ local function toggle_run_panel(is_debug)
return return
end end
local run_render = require('cp.run_render') local run_render = require('cp.runner.run_render')
run_render.setup_highlights() run_render.setup_highlights()
local test_state = run.get_run_panel_state() local test_state = run.get_run_panel_state()
@ -573,7 +573,7 @@ local function toggle_run_panel(is_debug)
config.hooks.before_debug(ctx) config.hooks.before_debug(ctx)
end end
local execute = require('cp.execute') local execute = require('cp.runner.execute')
local contest_config = config.contests[state.platform] local contest_config = config.contests[state.platform]
local compile_result = execute.compile_problem(ctx, contest_config, is_debug) local compile_result = execute.compile_problem(ctx, contest_config, is_debug)
if compile_result.success then if compile_result.success then
@ -586,7 +586,7 @@ local function toggle_run_panel(is_debug)
vim.schedule(function() vim.schedule(function()
if config.run_panel.ansi then if config.run_panel.ansi then
local ansi = require('cp.ansi') local ansi = require('cp.ui.ansi')
ansi.setup_highlight_groups() ansi.setup_highlight_groups()
end end
if current_diff_layout then if current_diff_layout then

View file

@ -89,7 +89,7 @@ function M.compile_generic(language_config, substitutions)
:wait() :wait()
local compile_time = (vim.uv.hrtime() - start_time) / 1000000 local compile_time = (vim.uv.hrtime() - start_time) / 1000000
local ansi = require('cp.ansi') local ansi = require('cp.ui.ansi')
result.stdout = ansi.bytes_to_string(result.stdout or '') result.stdout = ansi.bytes_to_string(result.stdout or '')
result.stderr = ansi.bytes_to_string(result.stderr or '') result.stderr = ansi.bytes_to_string(result.stderr or '')

View file

@ -194,7 +194,7 @@ local function run_single_test_case(ctx, contest_config, cp_config, test_case)
.system({ 'sh', '-c', table.concat(redirected_cmd, ' ') }, { text = false }) .system({ 'sh', '-c', table.concat(redirected_cmd, ' ') }, { text = false })
:wait() :wait()
local ansi = require('cp.ansi') local ansi = require('cp.ui.ansi')
compile_result.stdout = ansi.bytes_to_string(compile_result.stdout or '') compile_result.stdout = ansi.bytes_to_string(compile_result.stdout or '')
compile_result.stderr = ansi.bytes_to_string(compile_result.stderr or '') compile_result.stderr = ansi.bytes_to_string(compile_result.stderr or '')
@ -234,7 +234,7 @@ local function run_single_test_case(ctx, contest_config, cp_config, test_case)
:wait() :wait()
local execution_time = (vim.uv.hrtime() - start_time) / 1000000 local execution_time = (vim.uv.hrtime() - start_time) / 1000000
local ansi = require('cp.ansi') local ansi = require('cp.ui.ansi')
local stdout_str = ansi.bytes_to_string(result.stdout or '') local stdout_str = ansi.bytes_to_string(result.stdout or '')
local actual_output = stdout_str:gsub('\n$', '') local actual_output = stdout_str:gsub('\n$', '')
@ -365,7 +365,7 @@ function M.get_run_panel_state()
end end
function M.handle_compilation_failure(compilation_output) function M.handle_compilation_failure(compilation_output)
local ansi = require('cp.ansi') local ansi = require('cp.ui.ansi')
local config = require('cp.config').setup() local config = require('cp.config').setup()
local clean_text local clean_text

View file

@ -17,7 +17,7 @@ local problem = require('cp.problem')
local utils = require('cp.utils') local utils = require('cp.utils')
local function check_internet_connectivity() local function check_internet_connectivity()
local result = vim.system({ 'ping', '-c', '1', '-W', '3', '8.8.8.8' }, { text = true }):wait() local result = vim.system({ 'ping', '-c', '5', '-W', '3', '8.8.8.8' }, { text = true }):wait()
return result.code == 0 return result.code == 0
end end

View file

@ -75,7 +75,6 @@ function M.restore_layout(state, tile_fn)
local source_file local source_file
if source_files ~= '' then if source_files ~= '' then
local files = vim.split(source_files, '\n') local files = vim.split(source_files, '\n')
-- Prefer known extensions first, but accept any extension
local known_extensions = vim.tbl_keys(constants.filetype_to_language) local known_extensions = vim.tbl_keys(constants.filetype_to_language)
for _, file in ipairs(files) do for _, file in ipairs(files) do
local ext = vim.fn.fnamemodify(file, ':e') local ext = vim.fn.fnamemodify(file, ':e')

View file

@ -1,5 +1,5 @@
describe('ansi parser', function() describe('ansi parser', function()
local ansi = require('cp.ansi') local ansi = require('cp.ui.ansi')
describe('bytes_to_string', function() describe('bytes_to_string', function()
it('returns string as-is', function() it('returns string as-is', function()
@ -224,7 +224,6 @@ describe('ansi parser', function()
ansi.setup_highlight_groups() ansi.setup_highlight_groups()
local highlight = vim.api.nvim_get_hl(0, { name = 'CpAnsiRed' }) local highlight = vim.api.nvim_get_hl(0, { name = 'CpAnsiRed' })
-- When 'NONE' is set, nvim_get_hl returns nil for that field
assert.is_nil(highlight.fg) assert.is_nil(highlight.fg)
for i = 0, 15 do for i = 0, 15 do

View file

@ -4,7 +4,7 @@ describe('cp.diff', function()
before_each(function() before_each(function()
spec_helper.setup() spec_helper.setup()
diff = require('cp.diff') diff = require('cp.ui.diff')
end) end)
after_each(function() after_each(function()

View file

@ -6,7 +6,7 @@ describe('cp.execute', function()
before_each(function() before_each(function()
spec_helper.setup() spec_helper.setup()
execute = require('cp.execute') execute = require('cp.runner.execute')
mock_system_calls = {} mock_system_calls = {}
temp_files = {} temp_files = {}

View file

@ -4,7 +4,7 @@ describe('extmarks', function()
before_each(function() before_each(function()
spec_helper.setup() spec_helper.setup()
highlight = require('cp.highlight') highlight = require('cp.ui.highlight')
end) end)
after_each(function() after_each(function()

View file

@ -4,7 +4,7 @@ describe('cp.highlight', function()
before_each(function() before_each(function()
spec_helper.setup() spec_helper.setup()
highlight = require('cp.highlight') highlight = require('cp.ui.highlight')
end) end)
after_each(function() after_each(function()

View file

@ -1,5 +1,5 @@
describe('cp.run_render', function() describe('cp.run_render', function()
local run_render = require('cp.run_render') local run_render = require('cp.runner.run_render')
local spec_helper = require('spec.spec_helper') local spec_helper = require('spec.spec_helper')
before_each(function() before_each(function()

View file

@ -1,5 +1,5 @@
describe('run module', function() describe('run module', function()
local run = require('cp.run') local run = require('cp.runner.run')
describe('basic functionality', function() describe('basic functionality', function()
it('has required functions', function() it('has required functions', function()