From 9ea6f878dec312e4a70b2c59dd8074da2116db7e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 23:13:23 -0400 Subject: [PATCH 1/3] fix(config): extension is optional --- lua/cp/config.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 2da2ee0..c28407a 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -4,7 +4,7 @@ ---@field debug? string[] Debug command template ---@field executable? string Executable name ---@field version? number Language version ----@field extension string File extension +---@field extension? string File extension ---@class PartialLanguageConfig ---@field compile? string[] Compile command template @@ -17,7 +17,7 @@ ---@class ContestConfig ---@field cpp LanguageConfig ---@field python LanguageConfig ----@field default_language string +---@field default_language? string ---@class PartialContestConfig ---@field cpp? PartialLanguageConfig From b34ace85a5a17e13e3a0580edeec6a36eb2780c7 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 23:19:49 -0400 Subject: [PATCH 2/3] fix: cleanup config logic --- lua/cp/config.lua | 25 ------------------------- spec/config_spec.lua | 34 ++++++++++++---------------------- 2 files changed, 12 insertions(+), 47 deletions(-) diff --git a/lua/cp/config.lua b/lua/cp/config.lua index c28407a..b80d5ad 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -141,17 +141,6 @@ function M.setup(user_config) for lang_name, lang_config in pairs(config) do if type(lang_config) == 'table' then - if - lang_name ~= 'default_language' - and not vim.tbl_contains(vim.tbl_keys(constants.canonical_filetypes), lang_name) - then - return false, - ("Invalid language '%s'. Valid languages: %s"):format( - lang_name, - table.concat(vim.tbl_keys(constants.canonical_filetypes), ', ') - ) - end - if lang_config.extension and not vim.tbl_contains( @@ -168,20 +157,6 @@ function M.setup(user_config) end end - if - config.default_language - and not vim.tbl_contains( - vim.tbl_keys(constants.canonical_filetypes), - config.default_language - ) - then - return false, - ("Invalid default_language '%s'. Valid languages: %s"):format( - config.default_language, - table.concat(vim.tbl_keys(constants.canonical_filetypes), ', ') - ) - end - return true end, 'contest configuration', diff --git a/spec/config_spec.lua b/spec/config_spec.lua index e3011fc..b248fc5 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -157,7 +157,6 @@ describe('cp.config', function() contests = { test = { python = { test = { 'python3' } }, - rust = { compile = { 'rustc' } }, }, }, } @@ -192,36 +191,27 @@ describe('cp.config', function() assert.has_error(function() config.setup(invalid_config) - end, 'No language configurations found for test') + end, 'No language configurations found') end) - it('validates language names against canonical_filetypes', function() - local invalid_config = { - contests = { - test = { - invalid_lang = { compile = { 'gcc' } }, - }, - }, - } - - assert.has_error(function() - config.setup(invalid_config) - end, "Invalid language 'invalid_lang'") - end) - - it('validates default_language value', function() - local invalid_config = { + it('allows custom language names', function() + local user_config = { contests = { test = { + rust = { + compile = { 'rustc', '{source}', '-o', '{binary}' }, + test = { '{binary}' }, + extension = 'rs', + }, cpp = { compile = { 'g++' } }, - default_language = 'xd', }, }, } - assert.has_error(function() - config.setup(invalid_config) - end, "Invalid default_language 'xd'") + assert.has_no.errors(function() + local result = config.setup(user_config) + assert.equals('cpp', result.contests.test.default_language) + end) end) end) end) From ad3cd32bac24fe0466640e43f1a6929e35eba356 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 19 Sep 2025 23:22:24 -0400 Subject: [PATCH 3/3] fix(ci): relax extensino validation --- lua/cp/config.lua | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/lua/cp/config.lua b/lua/cp/config.lua index b80d5ad..e0b3a6c 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -139,23 +139,7 @@ function M.setup(user_config) return false end - for lang_name, lang_config in pairs(config) do - if type(lang_config) == 'table' then - if - lang_config.extension - and not vim.tbl_contains( - vim.tbl_keys(constants.filetype_to_language), - lang_config.extension - ) - then - return false, - ("Invalid extension '%s'. Valid extensions: %s"):format( - lang_config.extension, - table.concat(vim.tbl_keys(constants.filetype_to_language), ', ') - ) - end - end - end + -- Allow any language and extension configurations return true end,