feat(cache): cache clearing, updating and resetting
This commit is contained in:
parent
a40a53fafa
commit
78fb4f8f4b
10 changed files with 111 additions and 114 deletions
|
|
@ -342,4 +342,24 @@ function M.clear_contest_list(platform)
|
|||
end
|
||||
end
|
||||
|
||||
function M.clear_all()
|
||||
cache_data = {}
|
||||
M.save()
|
||||
end
|
||||
|
||||
---@param platform string
|
||||
function M.clear_platform(platform)
|
||||
vim.validate({
|
||||
platform = { platform, 'string' },
|
||||
})
|
||||
|
||||
if cache_data[platform] then
|
||||
cache_data[platform] = nil
|
||||
end
|
||||
if cache_data.contest_lists and cache_data.contest_lists[platform] then
|
||||
cache_data.contest_lists[platform] = nil
|
||||
end
|
||||
M.save()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ M.defaults = {
|
|||
filename = nil,
|
||||
run_panel = {
|
||||
ansi = true,
|
||||
diff_mode = 'vim',
|
||||
diff_mode = 'git',
|
||||
next_test_key = '<c-n>',
|
||||
prev_test_key = '<c-p>',
|
||||
toggle_diff_key = 't',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
M.PLATFORMS = { 'atcoder', 'codeforces', 'cses' }
|
||||
M.ACTIONS = { 'run', 'next', 'prev', 'pick' }
|
||||
M.ACTIONS = { 'run', 'next', 'prev', 'pick', 'cache' }
|
||||
|
||||
M.PLATFORM_DISPLAY_NAMES = {
|
||||
atcoder = 'AtCoder',
|
||||
|
|
|
|||
|
|
@ -294,6 +294,7 @@ local function toggle_run_panel(is_debug)
|
|||
|
||||
vim.api.nvim_set_current_win(parent_win)
|
||||
vim.cmd.split()
|
||||
vim.cmd('resize ' .. math.floor(vim.o.lines * 0.35))
|
||||
local actual_win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_buf(actual_win, actual_buf)
|
||||
|
||||
|
|
@ -341,6 +342,7 @@ local function toggle_run_panel(is_debug)
|
|||
|
||||
vim.api.nvim_set_current_win(parent_win)
|
||||
vim.cmd.split()
|
||||
vim.cmd('resize ' .. math.floor(vim.o.lines * 0.35))
|
||||
local diff_win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_buf(diff_win, diff_buf)
|
||||
|
||||
|
|
@ -375,6 +377,7 @@ local function toggle_run_panel(is_debug)
|
|||
|
||||
vim.api.nvim_set_current_win(parent_win)
|
||||
vim.cmd.split()
|
||||
vim.cmd('resize ' .. math.floor(vim.o.lines * 0.35))
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_buf(win, buf)
|
||||
vim.api.nvim_set_option_value('filetype', 'cptest', { buf = buf })
|
||||
|
|
@ -600,7 +603,7 @@ local function toggle_run_panel(is_debug)
|
|||
state.test_buffers = test_buffers
|
||||
state.test_windows = test_windows
|
||||
local test_state = run.get_run_panel_state()
|
||||
logger.log(string.format('test panel opened (%d test cases)', #test_state.test_cases))
|
||||
logger.log(string.format('test panel opened (%d test cases)', #test_state.test_cases), vim.log.levels.INFO)
|
||||
end
|
||||
|
||||
---@param contest_id string
|
||||
|
|
@ -751,6 +754,26 @@ local function handle_pick_action()
|
|||
end
|
||||
end
|
||||
|
||||
local function handle_cache_command(cmd)
|
||||
if cmd.subcommand == 'clear' then
|
||||
cache.load()
|
||||
if cmd.platform then
|
||||
if vim.tbl_contains(platforms, cmd.platform) then
|
||||
cache.clear_platform(cmd.platform)
|
||||
logger.log(('cleared cache for %s'):format(cmd.platform), vim.log.levels.INFO, true)
|
||||
else
|
||||
logger.log(
|
||||
('unknown platform: %s. Available: %s'):format(cmd.platform, table.concat(platforms, ', ')),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
end
|
||||
else
|
||||
cache.clear_all()
|
||||
logger.log('cleared all cache', vim.log.levels.INFO, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function restore_from_current_file()
|
||||
local current_file = vim.fn.expand('%:p')
|
||||
if current_file == '' then
|
||||
|
|
@ -820,7 +843,24 @@ local function parse_command(args)
|
|||
local first = filtered_args[1]
|
||||
|
||||
if vim.tbl_contains(actions, first) then
|
||||
return { type = 'action', action = first, language = language, debug = debug }
|
||||
if first == 'cache' then
|
||||
local subcommand = filtered_args[2]
|
||||
if not subcommand then
|
||||
return { type = 'error', message = 'cache command requires subcommand: clear' }
|
||||
end
|
||||
if subcommand == 'clear' then
|
||||
local platform = filtered_args[3]
|
||||
return {
|
||||
type = 'cache',
|
||||
subcommand = 'clear',
|
||||
platform = platform
|
||||
}
|
||||
else
|
||||
return { type = 'error', message = 'unknown cache subcommand: ' .. subcommand }
|
||||
end
|
||||
else
|
||||
return { type = 'action', action = first, language = language, debug = debug }
|
||||
end
|
||||
end
|
||||
|
||||
if vim.tbl_contains(platforms, first) then
|
||||
|
|
@ -896,6 +936,11 @@ function M.handle_command(opts)
|
|||
return
|
||||
end
|
||||
|
||||
if cmd.type == 'cache' then
|
||||
handle_cache_command(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
if cmd.type == 'platform_only' then
|
||||
set_platform(cmd.platform)
|
||||
return
|
||||
|
|
@ -929,7 +974,9 @@ function M.handle_command(opts)
|
|||
#metadata_result.problems,
|
||||
cmd.platform,
|
||||
cmd.contest
|
||||
)
|
||||
),
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
problem_ids = vim.tbl_map(function(prob)
|
||||
return prob.id
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ function M.compile_generic(language_config, substitutions)
|
|||
result.stderr = ansi.bytes_to_string(result.stderr or '')
|
||||
|
||||
if result.code == 0 then
|
||||
logger.log(('compilation successful (%.1fms)'):format(compile_time))
|
||||
logger.log(('compilation successful (%.1fms)'):format(compile_time), vim.log.levels.INFO)
|
||||
else
|
||||
logger.log(('compilation failed (%.1fms)'):format(compile_time))
|
||||
end
|
||||
|
|
@ -235,7 +235,7 @@ function M.compile_problem(ctx, contest_config, is_debug)
|
|||
if compile_result.code ~= 0 then
|
||||
return { success = false, output = compile_result.stdout or 'unknown error' }
|
||||
end
|
||||
logger.log(('compilation successful (%s)'):format(is_debug and 'debug mode' or 'test mode'))
|
||||
logger.log(('compilation successful (%s)'):format(is_debug and 'debug mode' or 'test mode'), vim.log.levels.INFO)
|
||||
end
|
||||
|
||||
return { success = true, output = nil }
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ function M.load_test_cases(ctx, state)
|
|||
run_panel_state.constraints.memory_mb
|
||||
)
|
||||
or ''
|
||||
logger.log(('loaded %d test case(s)%s'):format(#test_cases, constraint_info))
|
||||
logger.log(('loaded %d test case(s)%s'):format(#test_cases, constraint_info), vim.log.levels.INFO)
|
||||
return #test_cases > 0
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue