possibly working
This commit is contained in:
parent
545793df39
commit
f9cf5b1614
5 changed files with 20 additions and 75 deletions
|
|
@ -109,9 +109,7 @@ local function parse_command(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.handle_command(opts)
|
function M.handle_command(opts)
|
||||||
logger.log(('command received: %s'):format(vim.inspect(opts.fargs)))
|
|
||||||
local cmd = parse_command(opts.fargs)
|
local cmd = parse_command(opts.fargs)
|
||||||
logger.log(('parsed command: %s'):format(vim.inspect(cmd)))
|
|
||||||
|
|
||||||
if cmd.type == 'error' then
|
if cmd.type == 'error' then
|
||||||
logger.log(cmd.message, vim.log.levels.ERROR)
|
logger.log(cmd.message, vim.log.levels.ERROR)
|
||||||
|
|
@ -125,19 +123,14 @@ function M.handle_command(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmd.type == 'action' then
|
if cmd.type == 'action' then
|
||||||
logger.log(('handling action: %s'):format(cmd.action))
|
|
||||||
local setup = require('cp.setup')
|
local setup = require('cp.setup')
|
||||||
local ui = require('cp.ui.panel')
|
local ui = require('cp.ui.panel')
|
||||||
|
|
||||||
if cmd.action == 'run' then
|
if cmd.action == 'run' then
|
||||||
print('running')
|
|
||||||
logger.log('calling toggle_run_panel')
|
|
||||||
ui.toggle_run_panel(cmd.debug)
|
ui.toggle_run_panel(cmd.debug)
|
||||||
elseif cmd.action == 'next' then
|
elseif cmd.action == 'next' then
|
||||||
logger.log('calling navigate_problem(1)')
|
|
||||||
setup.navigate_problem(1, cmd.language)
|
setup.navigate_problem(1, cmd.language)
|
||||||
elseif cmd.action == 'prev' then
|
elseif cmd.action == 'prev' then
|
||||||
logger.log('calling navigate_problem(-1)')
|
|
||||||
setup.navigate_problem(-1, cmd.language)
|
setup.navigate_problem(-1, cmd.language)
|
||||||
elseif cmd.action == 'pick' then
|
elseif cmd.action == 'pick' then
|
||||||
local picker = require('cp.commands.picker')
|
local picker = require('cp.commands.picker')
|
||||||
|
|
|
||||||
|
|
@ -87,14 +87,11 @@ end
|
||||||
---@param expected_file string
|
---@param expected_file string
|
||||||
---@return TestCase[]
|
---@return TestCase[]
|
||||||
local function parse_test_cases_from_files(input_file, expected_file)
|
local function parse_test_cases_from_files(input_file, expected_file)
|
||||||
if vim.fn.filereadable(input_file) == 0 or vim.fn.filereadable(expected_file) == 0 then
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
|
|
||||||
local base_name = vim.fn.fnamemodify(input_file, ':r')
|
local base_name = vim.fn.fnamemodify(input_file, ':r')
|
||||||
local test_cases = {}
|
local test_cases = {}
|
||||||
local i = 1
|
|
||||||
|
|
||||||
|
-- Try numbered files first (created by scraper)
|
||||||
|
local i = 1
|
||||||
while true do
|
while true do
|
||||||
local individual_input_file = base_name .. '.' .. i .. '.cpin'
|
local individual_input_file = base_name .. '.' .. i .. '.cpin'
|
||||||
local individual_expected_file = base_name .. '.' .. i .. '.cpout'
|
local individual_expected_file = base_name .. '.' .. i .. '.cpout'
|
||||||
|
|
@ -113,12 +110,6 @@ local function parse_test_cases_from_files(input_file, expected_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #test_cases == 0 then
|
|
||||||
local input_content = table.concat(vim.fn.readfile(input_file), '\n')
|
|
||||||
local expected_content = table.concat(vim.fn.readfile(expected_file), '\n')
|
|
||||||
return { create_test_case(1, input_content, expected_content) }
|
|
||||||
end
|
|
||||||
|
|
||||||
return test_cases
|
return test_cases
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,11 +91,6 @@ function M.scrape_problem_tests(platform, contest_id, problem_id, callback)
|
||||||
if mkdir_ok then
|
if mkdir_ok then
|
||||||
local config = require('cp.config')
|
local config = require('cp.config')
|
||||||
local base_name = config.default_filename(contest_id, problem_id)
|
local base_name = config.default_filename(contest_id, problem_id)
|
||||||
local logger = require('cp.log')
|
|
||||||
|
|
||||||
logger.log(
|
|
||||||
('writing %d test files for %s (base: %s)'):format(#result.tests, problem_id, base_name)
|
|
||||||
)
|
|
||||||
|
|
||||||
for i, test_case in ipairs(result.tests) do
|
for i, test_case in ipairs(result.tests) do
|
||||||
local input_file = 'io/' .. base_name .. '.' .. i .. '.cpin'
|
local input_file = 'io/' .. base_name .. '.' .. i .. '.cpin'
|
||||||
|
|
@ -104,24 +99,10 @@ function M.scrape_problem_tests(platform, contest_id, problem_id, callback)
|
||||||
local input_content = test_case.input:gsub('\r', '')
|
local input_content = test_case.input:gsub('\r', '')
|
||||||
local expected_content = test_case.expected:gsub('\r', '')
|
local expected_content = test_case.expected:gsub('\r', '')
|
||||||
|
|
||||||
local input_ok =
|
|
||||||
pcall(vim.fn.writefile, vim.split(input_content, '\n', true), input_file)
|
pcall(vim.fn.writefile, vim.split(input_content, '\n', true), input_file)
|
||||||
local expected_ok =
|
|
||||||
pcall(vim.fn.writefile, vim.split(expected_content, '\n', true), expected_file)
|
pcall(vim.fn.writefile, vim.split(expected_content, '\n', true), expected_file)
|
||||||
|
|
||||||
if input_ok and expected_ok then
|
|
||||||
logger.log(('wrote test files: %s, %s'):format(input_file, expected_file))
|
|
||||||
else
|
|
||||||
logger.log(
|
|
||||||
('failed to write test files for %s.%d'):format(base_name, i),
|
|
||||||
vim.log.levels.WARN
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
local logger = require('cp.log')
|
|
||||||
logger.log('failed to create io/ directory', vim.log.levels.ERROR)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local cached_tests = {}
|
local cached_tests = {}
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,6 @@ function M.setup_problem(contest_id, problem_id, language)
|
||||||
logger.log('loading test cases...')
|
logger.log('loading test cases...')
|
||||||
|
|
||||||
scraper.scrape_problem_tests(platform, contest_id, problem_id, function(result)
|
scraper.scrape_problem_tests(platform, contest_id, problem_id, function(result)
|
||||||
vim.schedule(function()
|
|
||||||
if result.success then
|
if result.success then
|
||||||
logger.log(('loaded %d test cases for %s'):format(#(result.tests or {}), problem_id))
|
logger.log(('loaded %d test cases for %s'):format(#(result.tests or {}), problem_id))
|
||||||
if state.get_problem_id() == problem_id then
|
if state.get_problem_id() == problem_id then
|
||||||
|
|
@ -124,7 +123,6 @@ function M.setup_problem(contest_id, problem_id, language)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
|
||||||
else
|
else
|
||||||
logger.log(('scraping disabled for %s'):format(platform))
|
logger.log(('scraping disabled for %s'):format(platform))
|
||||||
state.set_test_cases({})
|
state.set_test_cases({})
|
||||||
|
|
@ -202,20 +200,9 @@ function M.scrape_remaining_problems(platform, contest_id, problems)
|
||||||
logger.log(('scraping %d uncached problems in background...'):format(#missing_problems))
|
logger.log(('scraping %d uncached problems in background...'):format(#missing_problems))
|
||||||
|
|
||||||
for _, prob in ipairs(missing_problems) do
|
for _, prob in ipairs(missing_problems) do
|
||||||
logger.log(('starting background scrape for problem %s'):format(prob.id))
|
|
||||||
scraper.scrape_problem_tests(platform, contest_id, prob.id, function(result)
|
scraper.scrape_problem_tests(platform, contest_id, prob.id, function(result)
|
||||||
if result.success then
|
if result.success then
|
||||||
logger.log(
|
logger.log(('background: scraped problem %s'):format(prob.id))
|
||||||
('background: scraped problem %s - %d test cases'):format(prob.id, #(result.tests or {}))
|
|
||||||
)
|
|
||||||
else
|
|
||||||
logger.log(
|
|
||||||
('background: failed to scrape problem %s: %s'):format(
|
|
||||||
prob.id,
|
|
||||||
result.error or 'unknown error'
|
|
||||||
),
|
|
||||||
vim.log.levels.WARN
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
@ -260,8 +247,6 @@ function M.navigate_problem(direction, language)
|
||||||
|
|
||||||
local new_problem = problems[new_index]
|
local new_problem = problems[new_index]
|
||||||
M.setup_problem(contest_id, new_problem.id, language)
|
M.setup_problem(contest_id, new_problem.id, language)
|
||||||
|
|
||||||
state.set_problem_id(new_problem.id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ local function get_current_problem()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.toggle_run_panel(is_debug)
|
function M.toggle_run_panel(is_debug)
|
||||||
if state.run_panel_active then
|
if state.is_run_panel_active() then
|
||||||
if current_diff_layout then
|
if current_diff_layout then
|
||||||
current_diff_layout.cleanup()
|
current_diff_layout.cleanup()
|
||||||
current_diff_layout = nil
|
current_diff_layout = nil
|
||||||
|
|
@ -27,15 +27,12 @@ function M.toggle_run_panel(is_debug)
|
||||||
state.saved_session = nil
|
state.saved_session = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
print('run panel was active, returning')
|
|
||||||
|
|
||||||
state.set_run_panel_active(false)
|
state.set_run_panel_active(false)
|
||||||
logger.log('test panel closed')
|
logger.log('test panel closed')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not state.get_platform() then
|
if not state.get_platform() then
|
||||||
print('no panel active, returning')
|
|
||||||
logger.log(
|
logger.log(
|
||||||
'No contest configured. Use :CP <platform> <contest> <problem> to set up first.',
|
'No contest configured. Use :CP <platform> <contest> <problem> to set up first.',
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
|
|
@ -44,9 +41,7 @@ function M.toggle_run_panel(is_debug)
|
||||||
end
|
end
|
||||||
|
|
||||||
local problem_id = get_current_problem()
|
local problem_id = get_current_problem()
|
||||||
print(problem_id)
|
|
||||||
if not problem_id then
|
if not problem_id then
|
||||||
logger.log('no current problem set', vim.log.levels.ERROR)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -205,7 +200,7 @@ function M.toggle_run_panel(is_debug)
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(test_windows.tab_win)
|
vim.api.nvim_set_current_win(test_windows.tab_win)
|
||||||
|
|
||||||
state.run_panel_active = true
|
state.set_run_panel_active(true)
|
||||||
state.test_buffers = test_buffers
|
state.test_buffers = test_buffers
|
||||||
state.test_windows = test_windows
|
state.test_windows = test_windows
|
||||||
local test_state = run.get_run_panel_state()
|
local test_state = run.get_run_panel_state()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue