more typechecking
This commit is contained in:
parent
17cdbf0a50
commit
b3ffef7341
4 changed files with 15 additions and 35 deletions
18
doc/cp.txt
18
doc/cp.txt
|
|
@ -160,24 +160,12 @@ Optional configuration with lazy.nvim: >
|
||||||
|
|
||||||
Fields: ~
|
Fields: ~
|
||||||
• {before_run}? (`function`) Called before `:CP run`.
|
• {before_run}? (`function`) Called before `:CP run`.
|
||||||
`function(ctx: HookContext)`
|
`function(ctx: ProblemContext)`
|
||||||
• {before_debug}? (`function`) Called before `:CP debug`.
|
• {before_debug}? (`function`) Called before `:CP debug`.
|
||||||
`function(ctx: HookContext)`
|
`function(ctx: ProblemContext)`
|
||||||
• {setup_code}? (`function`) Called after source file is opened.
|
• {setup_code}? (`function`) Called after source file is opened.
|
||||||
Used to configure buffer settings.
|
Used to configure buffer settings.
|
||||||
`function(ctx: HookContext)`
|
`function(ctx: ProblemContext)`
|
||||||
|
|
||||||
*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.
|
|
||||||
|
|
||||||
WORKFLOW *cp-workflow*
|
WORKFLOW *cp-workflow*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,10 @@
|
||||||
---@field default_language? string
|
---@field default_language? string
|
||||||
---@field timeout_ms? number
|
---@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
|
---@class Hooks
|
||||||
---@field before_run? fun(ctx: HookContext)
|
---@field before_run? fun(ctx: ProblemContext)
|
||||||
---@field before_debug? fun(ctx: HookContext)
|
---@field before_debug? fun(ctx: ProblemContext)
|
||||||
---@field setup_code? fun(ctx: HookContext)
|
---@field setup_code? fun(ctx: ProblemContext)
|
||||||
|
|
||||||
---@class cp.Config
|
---@class cp.Config
|
||||||
---@field contests table<string, ContestConfig>
|
---@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 contest_name, contest_config in pairs(user_config.contests) do
|
||||||
for lang_name, lang_config in pairs(contest_config) do
|
for lang_name, lang_config in pairs(contest_config) do
|
||||||
if type(lang_config) == "table" and lang_config.extension then
|
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(
|
error(
|
||||||
("Invalid extension '%s' for language '%s' in contest '%s'. Valid extensions: %s"):format(
|
("Invalid extension '%s' for language '%s' in contest '%s'. Valid extensions: %s"):format(
|
||||||
lang_config.extension,
|
lang_config.extension,
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,9 @@ local function compile_generic(language_config, substitutions)
|
||||||
local compile_cmd = substitute_template(language_config.compile, substitutions)
|
local compile_cmd = substitute_template(language_config.compile, substitutions)
|
||||||
logger.log(("compiling: %s"):format(table.concat(compile_cmd, " ")))
|
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 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
|
if result.code == 0 then
|
||||||
logger.log(("compilation successful (%.1fms)"):format(compile_time))
|
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, " ")))
|
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, {
|
local result = vim.system(cmd, {
|
||||||
stdin = input_data,
|
stdin = input_data,
|
||||||
|
|
@ -137,7 +137,7 @@ local function execute_command(cmd, input_data, timeout_ms)
|
||||||
text = true,
|
text = true,
|
||||||
}):wait()
|
}):wait()
|
||||||
|
|
||||||
local end_time = vim.loop.hrtime()
|
local end_time = vim.uv.hrtime()
|
||||||
local execution_time = (end_time - start_time) / 1000000
|
local execution_time = (end_time - start_time) / 1000000
|
||||||
|
|
||||||
local actual_code = result.code or 0
|
local actual_code = result.code or 0
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ local function set_platform(platform)
|
||||||
end
|
end
|
||||||
|
|
||||||
state.platform = platform
|
state.platform = platform
|
||||||
vim.fn.mkdir("build", "p")
|
vim.fs.mkdir("build", { parents = true })
|
||||||
vim.fn.mkdir("io", "p")
|
vim.fs.mkdir("io", { parents = true })
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue