more typechecking

This commit is contained in:
Barrett Ruth 2025-09-15 14:11:12 -04:00
parent 17cdbf0a50
commit b3ffef7341
4 changed files with 15 additions and 35 deletions

View file

@ -160,24 +160,12 @@ Optional configuration with lazy.nvim: >
Fields: ~
• {before_run}? (`function`) Called before `:CP run`.
`function(ctx: HookContext)`
`function(ctx: ProblemContext)`
• {before_debug}? (`function`) Called before `:CP debug`.
`function(ctx: HookContext)`
`function(ctx: ProblemContext)`
• {setup_code}? (`function`) Called after source file is opened.
Used to configure buffer settings.
`function(ctx: HookContext)`
*cp.HookContext*
Fields: ~
• {problem_id} (`string`) Problem identifier (e.g. "a", "b").
• {platform} (`string`) Platform name (e.g. "codeforces").
• {contest_id} (`string`) Contest identifier (e.g. "1933").
• {source_file} (`string`) Path to source file.
• {input_file} (`string`) Path to input file (.cpin).
• {output_file} (`string`) Path to output file (.cpout).
• {expected_file} (`string`) Path to expected output file.
• {contest_config} (`table`) Contest configuration.
`function(ctx: ProblemContext)`
WORKFLOW *cp-workflow*

View file

@ -26,20 +26,10 @@
---@field default_language? string
---@field timeout_ms? number
---@class HookContext
---@field problem_id string
---@field platform string
---@field contest_id string
---@field source_file string
---@field input_file string
---@field output_file string
---@field expected_file string
---@field contest_config table
---@class Hooks
---@field before_run? fun(ctx: HookContext)
---@field before_debug? fun(ctx: HookContext)
---@field setup_code? fun(ctx: HookContext)
---@field before_run? fun(ctx: ProblemContext)
---@field before_debug? fun(ctx: ProblemContext)
---@field setup_code? fun(ctx: ProblemContext)
---@class cp.Config
---@field contests table<string, ContestConfig>
@ -103,7 +93,9 @@ function M.setup(user_config)
for contest_name, contest_config in pairs(user_config.contests) do
for lang_name, lang_config in pairs(contest_config) do
if type(lang_config) == "table" and lang_config.extension then
if not vim.tbl_contains(vim.tbl_keys(languages.filetype_to_language), lang_config.extension) then
if
not vim.tbl_contains(vim.tbl_keys(languages.filetype_to_language), lang_config.extension)
then
error(
("Invalid extension '%s' for language '%s' in contest '%s'. Valid extensions: %s"):format(
lang_config.extension,

View file

@ -103,9 +103,9 @@ local function compile_generic(language_config, substitutions)
local compile_cmd = substitute_template(language_config.compile, substitutions)
logger.log(("compiling: %s"):format(table.concat(compile_cmd, " ")))
local start_time = vim.loop.hrtime()
local start_time = vim.uv.hrtime()
local result = vim.system(compile_cmd, { text = true }):wait()
local compile_time = (vim.loop.hrtime() - start_time) / 1000000
local compile_time = (vim.uv.hrtime() - start_time) / 1000000
if result.code == 0 then
logger.log(("compilation successful (%.1fms)"):format(compile_time))
@ -129,7 +129,7 @@ local function execute_command(cmd, input_data, timeout_ms)
logger.log(("executing: %s"):format(table.concat(cmd, " ")))
local start_time = vim.loop.hrtime()
local start_time = vim.uv.hrtime()
local result = vim.system(cmd, {
stdin = input_data,
@ -137,7 +137,7 @@ local function execute_command(cmd, input_data, timeout_ms)
text = true,
}):wait()
local end_time = vim.loop.hrtime()
local end_time = vim.uv.hrtime()
local execution_time = (end_time - start_time) / 1000000
local actual_code = result.code or 0

View file

@ -41,8 +41,8 @@ local function set_platform(platform)
end
state.platform = platform
vim.fn.mkdir("build", "p")
vim.fn.mkdir("io", "p")
vim.fs.mkdir("build", { parents = true })
vim.fs.mkdir("io", { parents = true })
return true
end