From f22eccfa8954e71338cffaca6eab04fbab889be6 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 19:40:50 -0400 Subject: [PATCH 1/3] feat(run_panel): max_output_lines --- lua/cp/config.lua | 9 +++++++++ lua/cp/test.lua | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lua/cp/config.lua b/lua/cp/config.lua index d92c267..0616e9f 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -36,6 +36,7 @@ ---@field next_test_key string Key to navigate to next test case ---@field prev_test_key string Key to navigate to previous test case ---@field toggle_diff_key string Key to toggle diff mode +---@field max_output_lines number Maximum lines of test output to display ---@class DiffGitConfig ---@field command string Git executable name @@ -84,6 +85,7 @@ M.defaults = { next_test_key = '', prev_test_key = '', toggle_diff_key = 't', + max_output_lines = 50, }, diff = { git = { @@ -203,6 +205,13 @@ function M.setup(user_config) end, 'toggle_diff_key must be a non-empty string', }, + max_output_lines = { + config.run_panel.max_output_lines, + function(value) + return type(value) == 'number' and value > 0 and value == math.floor(value) + end, + 'max_output_lines must be a positive integer', + }, }) vim.validate({ diff --git a/lua/cp/test.lua b/lua/cp/test.lua index 329f03c..385a105 100644 --- a/lua/cp/test.lua +++ b/lua/cp/test.lua @@ -118,7 +118,7 @@ end ---@param contest_config ContestConfig ---@param test_case TestCase ---@return table -local function run_single_test_case(ctx, contest_config, test_case) +local function run_single_test_case(ctx, contest_config, cp_config, test_case) local language = vim.fn.fnamemodify(ctx.source_file, ':e') local language_name = constants.filetype_to_language[language] or contest_config.default_language local language_config = contest_config[language_name] @@ -187,6 +187,18 @@ local function run_single_test_case(ctx, contest_config, test_case) local execution_time = (vim.uv.hrtime() - start_time) / 1000000 local actual_output = (result.stdout or ''):gsub('\n$', '') + + local max_lines = cp_config.run_panel.max_output_lines + local output_lines = vim.split(actual_output, '\n') + if #output_lines > max_lines then + local trimmed_lines = {} + for i = 1, max_lines do + table.insert(trimmed_lines, output_lines[i]) + end + table.insert(trimmed_lines, string.format('... (output trimmed after %d lines)', max_lines)) + actual_output = table.concat(trimmed_lines, '\n') + end + local expected_output = test_case.expected:gsub('\n$', '') local ok = actual_output == expected_output @@ -238,7 +250,7 @@ end ---@param contest_config ContestConfig ---@param index number ---@return boolean -function M.run_test_case(ctx, contest_config, index) +function M.run_test_case(ctx, contest_config, cp_config, index) local test_case = run_panel_state.test_cases[index] if not test_case then return false From 2613399d01c56258ca7dda9deb3e81d90af4c6aa Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 19:43:06 -0400 Subject: [PATCH 2/3] feat(run_panel): max_output_lines --- doc/cp.txt | 1 + lua/cp/init.lua | 2 +- lua/cp/test.lua | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/cp.txt b/doc/cp.txt index 64f4609..6e4983d 100644 --- a/doc/cp.txt +++ b/doc/cp.txt @@ -117,6 +117,7 @@ Here's an example configuration with lazy.nvim: > next_test_key = "", prev_test_key = "", toggle_diff_key = "t", + max_output_lines = 50, }, diff = { git = { diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 54b75e4..dda2b2e 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -470,7 +470,7 @@ local function toggle_run_panel(is_debug) local execute_module = require('cp.execute') local contest_config = config.contests[state.platform] if execute_module.compile_problem(ctx, contest_config, is_debug) then - test_module.run_all_test_cases(ctx, contest_config) + test_module.run_all_test_cases(ctx, contest_config, config) end refresh_run_panel() diff --git a/lua/cp/test.lua b/lua/cp/test.lua index 385a105..3e0e147 100644 --- a/lua/cp/test.lua +++ b/lua/cp/test.lua @@ -259,7 +259,7 @@ function M.run_test_case(ctx, contest_config, cp_config, index) logger.log(('running test case %d'):format(index)) test_case.status = 'running' - local result = run_single_test_case(ctx, contest_config, test_case) + local result = run_single_test_case(ctx, contest_config, cp_config, test_case) test_case.status = result.status test_case.actual = result.actual @@ -276,10 +276,10 @@ end ---@param ctx ProblemContext ---@param contest_config ContestConfig ---@return TestCase[] -function M.run_all_test_cases(ctx, contest_config) +function M.run_all_test_cases(ctx, contest_config, cp_config) local results = {} for i, _ in ipairs(run_panel_state.test_cases) do - M.run_test_case(ctx, contest_config, i) + M.run_test_case(ctx, contest_config, cp_config, i) table.insert(results, run_panel_state.test_cases[i]) end return results From e8157a54912afe5ff76f51bb44fd0d497b7d486f Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 19:43:37 -0400 Subject: [PATCH 3/3] feat(doc): max output line config option --- doc/cp.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/cp.txt b/doc/cp.txt index 6e4983d..32bb734 100644 --- a/doc/cp.txt +++ b/doc/cp.txt @@ -178,6 +178,7 @@ Here's an example configuration with lazy.nvim: > • {next_test_key} (`string`, default: `""`) Key to navigate to next test case. • {prev_test_key} (`string`, default: `""`) Key to navigate to previous test case. • {toggle_diff_key} (`string`, default: `"t"`) Key to toggle diff mode between vim and git. + • {max_output_lines} (`number`, default: `50`) Maximum lines of test output to display. *cp.DiffConfig*