feat: refactors
This commit is contained in:
parent
d4c5f08b5f
commit
4c5c44742e
3 changed files with 98 additions and 93 deletions
|
|
@ -142,7 +142,7 @@ function M.run(cmd, stdin, timeout_ms, memory_mb, on_complete)
|
||||||
or lower:find('enomem', 1, true)
|
or lower:find('enomem', 1, true)
|
||||||
local near_cap = peak_mb >= (0.90 * memory_mb)
|
local near_cap = peak_mb >= (0.90 * memory_mb)
|
||||||
|
|
||||||
local mled = (peak_mb >= memory_mb) or near_cap or (oom_hint and not tled)
|
local mled = (peak_mb >= memory_mb) or near_cap or (oom_hint ~= nil and not tled)
|
||||||
|
|
||||||
if tled then
|
if tled then
|
||||||
logger.log(('Execution timed out in %.1fms.'):format(dt))
|
logger.log(('Execution timed out in %.1fms.'):format(dt))
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ end
|
||||||
|
|
||||||
---@param test_case RanTestCase
|
---@param test_case RanTestCase
|
||||||
---@param debug boolean?
|
---@param debug boolean?
|
||||||
---@param on_complete fun(result: { status: "pass"|"fail"|"tle"|"mle", actual: string, actual_highlights: Highlight[], error: string, stderr: string, time_ms: number, code: integer, ok: boolean, signal: string, tled: boolean, mled: boolean, rss_mb: number })
|
---@param on_complete fun(result: { status: "pass"|"fail"|"tle"|"mle", actual: string, actual_highlights: Highlight[], error: string, stderr: string, time_ms: number, code: integer, ok: boolean, signal: string?, tled: boolean, mled: boolean, rss_mb: number })
|
||||||
local function run_single_test_case(test_case, debug, on_complete)
|
local function run_single_test_case(test_case, debug, on_complete)
|
||||||
local source_file = state.get_source_file()
|
local source_file = state.get_source_file()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,26 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
|
|
||||||
local execute = require('cp.runner.execute')
|
local execute = require('cp.runner.execute')
|
||||||
local run = require('cp.runner.run')
|
local run = require('cp.runner.run')
|
||||||
local compile_result = execute.compile_problem()
|
|
||||||
|
local function restore_session()
|
||||||
|
if state.saved_interactive_session then
|
||||||
|
vim.cmd.source(state.saved_interactive_session)
|
||||||
|
vim.fn.delete(state.saved_interactive_session)
|
||||||
|
state.saved_interactive_session = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
execute.compile_problem(false, function(compile_result)
|
||||||
if not compile_result.success then
|
if not compile_result.success then
|
||||||
run.handle_compilation_failure(compile_result.output)
|
run.handle_compilation_failure(compile_result.output)
|
||||||
|
restore_session()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local binary = state.get_binary_file()
|
local binary = state.get_binary_file()
|
||||||
if not binary or binary == '' then
|
if not binary or binary == '' then
|
||||||
logger.log('No binary produced.', vim.log.levels.ERROR)
|
logger.log('No binary produced.', vim.log.levels.ERROR)
|
||||||
|
restore_session()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -104,14 +115,11 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
("Interactor '%s' is not executable."):format(interactor_cmd),
|
("Interactor '%s' is not executable."):format(interactor_cmd),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
if state.saved_interactive_session then
|
restore_session()
|
||||||
vim.cmd.source(state.saved_interactive_session)
|
|
||||||
vim.fn.delete(state.saved_interactive_session)
|
|
||||||
state.saved_interactive_session = nil
|
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local orchestrator = vim.fn.fnamemodify(utils.get_plugin_path() .. '/scripts/interact.py', ':p')
|
local orchestrator =
|
||||||
|
vim.fn.fnamemodify(utils.get_plugin_path() .. '/scripts/interact.py', ':p')
|
||||||
cmdline = table.concat({
|
cmdline = table.concat({
|
||||||
'uv',
|
'uv',
|
||||||
'run',
|
'run',
|
||||||
|
|
@ -139,11 +147,7 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
pcall(vim.fn.jobstop, job)
|
pcall(vim.fn.jobstop, job)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if state.saved_interactive_session then
|
restore_session()
|
||||||
vim.cmd.source(state.saved_interactive_session)
|
|
||||||
vim.fn.delete(state.saved_interactive_session)
|
|
||||||
state.saved_interactive_session = nil
|
|
||||||
end
|
|
||||||
state.interactive_buf = nil
|
state.interactive_buf = nil
|
||||||
state.interactive_win = nil
|
state.interactive_win = nil
|
||||||
state.set_active_panel(nil)
|
state.set_active_panel(nil)
|
||||||
|
|
@ -189,6 +193,7 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
state.interactive_buf = term_buf
|
state.interactive_buf = term_buf
|
||||||
state.interactive_win = term_win
|
state.interactive_win = term_win
|
||||||
state.set_active_panel('interactive')
|
state.set_active_panel('interactive')
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return integer, integer
|
---@return integer, integer
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue