diff --git a/doc/cp.txt b/doc/cp.txt index be761d6..f3f97be 100644 --- a/doc/cp.txt +++ b/doc/cp.txt @@ -109,12 +109,11 @@ Template Variables ~ • {source} Source file path (e.g. "abc324a.cpp") • {binary} Output binary path (e.g. "build/abc324a.run") - • {version} Language version when specified in config • {contest} Contest identifier (e.g. "abc324", "1933") • {problem} Problem identifier (e.g. "a", "b") Example template: > - compile = { 'g++', '{source}', '-o', '{binary}', '-std=c++{version}' } + compile = { 'g++', '{source}', '-o', '{binary}', '-std=c++17' } < Would expand to: > g++ abc324a.cpp -o build/abc324a.run -std=c++17 < @@ -196,10 +195,9 @@ Here's an example configuration with lazy.nvim: >lua *cp.LanguageConfig* Fields: ~ {compile} (string[], optional) Compile command template with - {version}, {source}, {binary} placeholders. + {source}, {binary} placeholders. {test} (string[]) Test execution command template. {debug} (string[], optional) Debug compile command template. - {version} (number, optional) Language version (e.g. 20, 23 for C++). {extension} (string) File extension (e.g. "cc", "py"). {executable} (string, optional) Executable name for interpreted languages. diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 9935413..8efddb8 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -11,7 +11,6 @@ ---@field test? string[] Test execution command template ---@field debug? string[] Debug command template ---@field executable? string Executable name ----@field version? number Language version ---@field extension? string File extension ---@class ContestConfig diff --git a/lua/cp/runner/execute.lua b/lua/cp/runner/execute.lua index e4bb416..8668b8f 100644 --- a/lua/cp/runner/execute.lua +++ b/lua/cp/runner/execute.lua @@ -230,7 +230,6 @@ function M.compile_problem(contest_config, is_debug) local substitutions = { source = source_file, binary = binary_file, - version = tostring(language_config.version), } local compile_cmd = (is_debug and language_config.debug) and language_config.debug @@ -279,7 +278,6 @@ function M.run_problem(contest_config, is_debug) local substitutions = { source = source_file, binary = binary_file, - version = tostring(language_config.version), } local compile_cmd = is_debug and language_config.debug or language_config.compile @@ -302,6 +300,11 @@ function M.run_problem(contest_config, is_debug) local platform = state.get_platform() local contest_id = state.get_contest_id() local problem_id = state.get_problem_id() + + if not platform or not contest_id then + logger.log('configure a contest before running a problem', vim.log.levels.ERROR) + return + end local timeout_ms, _ = cache.get_constraints(platform, contest_id, problem_id) timeout_ms = timeout_ms or 2000 diff --git a/lua/cp/runner/run.lua b/lua/cp/runner/run.lua index cb1bce2..21cf19a 100644 --- a/lua/cp/runner/run.lua +++ b/lua/cp/runner/run.lua @@ -182,10 +182,9 @@ local function run_single_test_case(contest_config, cp_config, test_case) local substitutions = { source = source_file, binary = binary_file, - version = tostring(language_config.version or ''), } - if language_config.compile and vim.fn.filereadable(binary_file) == 0 then + if language_config.compile and binary_file and vim.fn.filereadable(binary_file) == 0 then logger.log('binary not found, compiling first...') local compile_cmd = substitute_template(language_config.compile, substitutions) local redirected_cmd = vim.deepcopy(compile_cmd)