feat(cache): update cache
This commit is contained in:
parent
b3168ff3f0
commit
3daf582b7a
5 changed files with 53 additions and 8 deletions
|
|
@ -109,10 +109,16 @@ COMMANDS *cp-commands*
|
|||
switching files to restore your CP environment.
|
||||
|
||||
Cache Commands ~
|
||||
:CP cache clear [contest]
|
||||
Clear the cache data for the specified contest,
|
||||
or all contests if none specified.
|
||||
|
||||
:CP cache clear [platform] [contest]
|
||||
Clear cache data at different granularities:
|
||||
• No args: Clear all cached data
|
||||
• [platform]: Clear all data for a platform
|
||||
• [platform] [contest]: Clear specific contest
|
||||
Examples: >
|
||||
:CP cache clear " Clear all
|
||||
:CP cache clear codeforces " Clear CF
|
||||
:CP cache clear codeforces 1848 " Clear CF 1848
|
||||
<
|
||||
:CP cache read
|
||||
View the cache in a pretty-printed lua buffer.
|
||||
Exit with q.
|
||||
|
|
|
|||
|
|
@ -39,7 +39,21 @@ function M.handle_cache_command(cmd)
|
|||
vim.api.nvim_set_current_buf(buf)
|
||||
elseif cmd.subcommand == 'clear' then
|
||||
cache.load()
|
||||
if cmd.platform then
|
||||
if cmd.platform and cmd.contest then
|
||||
if vim.tbl_contains(platforms, cmd.platform) then
|
||||
cache.clear_contest_data(cmd.platform, cmd.contest)
|
||||
logger.log(
|
||||
("Cache cleared for %s contest '%s'"):format(
|
||||
constants.PLATFORM_DISPLAY_NAMES[cmd.platform],
|
||||
cmd.contest
|
||||
),
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
else
|
||||
logger.log(("Unknown platform '%s'."):format(cmd.platform), vim.log.levels.ERROR)
|
||||
end
|
||||
elseif cmd.platform then
|
||||
if vim.tbl_contains(platforms, cmd.platform) then
|
||||
cache.clear_platform(cmd.platform)
|
||||
logger.log(
|
||||
|
|
|
|||
|
|
@ -40,10 +40,12 @@ local function parse_command(args)
|
|||
end
|
||||
if vim.tbl_contains({ 'clear', 'read' }, subcommand) then
|
||||
local platform = args[3]
|
||||
local contest = args[4]
|
||||
return {
|
||||
type = 'cache',
|
||||
subcommand = subcommand,
|
||||
platform = platform,
|
||||
contest = contest,
|
||||
}
|
||||
else
|
||||
return { type = 'error', message = 'unknown cache subcommand: ' .. subcommand }
|
||||
|
|
@ -55,6 +57,22 @@ local function parse_command(args)
|
|||
else
|
||||
return { type = 'action', action = 'interact' }
|
||||
end
|
||||
elseif first == 'edit' then
|
||||
local test_index = nil
|
||||
if #args >= 2 then
|
||||
local idx = tonumber(args[2])
|
||||
if not idx then
|
||||
return {
|
||||
type = 'error',
|
||||
message = ("Invalid argument '%s': expected test number"):format(args[2]),
|
||||
}
|
||||
end
|
||||
if idx < 1 or idx ~= math.floor(idx) then
|
||||
return { type = 'error', message = ("'%s' is not a valid test index"):format(idx) }
|
||||
end
|
||||
test_index = idx
|
||||
end
|
||||
return { type = 'action', action = 'edit', test_index = test_index }
|
||||
elseif first == 'run' or first == 'panel' then
|
||||
local debug = false
|
||||
local test_index = nil
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
M.PLATFORMS = { 'atcoder', 'codeforces', 'cses' }
|
||||
M.ACTIONS = { 'run', 'panel', 'next', 'prev', 'pick', 'cache', 'interact' }
|
||||
M.ACTIONS = { 'run', 'panel', 'next', 'prev', 'pick', 'cache', 'interact', 'edit' }
|
||||
|
||||
M.PLATFORM_DISPLAY_NAMES = {
|
||||
atcoder = 'AtCoder',
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ end, {
|
|||
end
|
||||
elseif num_args == 4 then
|
||||
if args[2] == 'cache' and args[3] == 'clear' then
|
||||
return filter_candidates(platforms)
|
||||
local candidates = vim.list_extend({}, platforms)
|
||||
table.insert(candidates, '')
|
||||
return filter_candidates(candidates)
|
||||
elseif args[3] == '--lang' then
|
||||
local platform = require('cp.state').get_platform()
|
||||
return filter_candidates(get_enabled_languages(platform))
|
||||
|
|
@ -115,7 +117,12 @@ end, {
|
|||
return filter_candidates(candidates)
|
||||
end
|
||||
elseif num_args == 5 then
|
||||
if vim.tbl_contains(platforms, args[2]) then
|
||||
if args[2] == 'cache' and args[3] == 'clear' and vim.tbl_contains(platforms, args[4]) then
|
||||
local cache = require('cp.cache')
|
||||
cache.load()
|
||||
local contests = cache.get_cached_contest_ids(args[4])
|
||||
return filter_candidates(contests)
|
||||
elseif vim.tbl_contains(platforms, args[2]) then
|
||||
if args[4] == '--lang' then
|
||||
return filter_candidates(get_enabled_languages(args[2]))
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue