fix(ci): unused variables
This commit is contained in:
parent
c68e6fbc19
commit
1b8365265d
6 changed files with 97 additions and 27 deletions
|
|
@ -7,6 +7,12 @@
|
|||
---@class CacheData
|
||||
---@field [string] table<string, ContestData>
|
||||
---@field file_states? table<string, FileState>
|
||||
---@field contest_lists? table<string, ContestListData>
|
||||
|
||||
---@class ContestListData
|
||||
---@field contests table[]
|
||||
---@field cached_at number
|
||||
---@field expires_at number
|
||||
|
||||
---@class ContestData
|
||||
---@field problems Problem[]
|
||||
|
|
@ -33,6 +39,12 @@ local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json'
|
|||
local cache_data = {}
|
||||
local loaded = false
|
||||
|
||||
local CONTEST_LIST_TTL = {
|
||||
cses = 7 * 24 * 60 * 60, -- 1 week
|
||||
codeforces = 24 * 60 * 60, -- 1 day
|
||||
atcoder = 24 * 60 * 60, -- 1 day
|
||||
}
|
||||
|
||||
---@param platform string
|
||||
---@return number?
|
||||
local function get_expiry_date(platform)
|
||||
|
|
@ -277,4 +289,57 @@ function M.set_file_state(file_path, platform, contest_id, problem_id, language)
|
|||
M.save()
|
||||
end
|
||||
|
||||
---@param platform string
|
||||
---@return table[]?
|
||||
function M.get_contest_list(platform)
|
||||
vim.validate({
|
||||
platform = { platform, 'string' },
|
||||
})
|
||||
|
||||
if not cache_data.contest_lists or not cache_data.contest_lists[platform] then
|
||||
return nil
|
||||
end
|
||||
|
||||
local contest_list_data = cache_data.contest_lists[platform]
|
||||
if os.time() >= contest_list_data.expires_at then
|
||||
return nil
|
||||
end
|
||||
|
||||
return contest_list_data.contests
|
||||
end
|
||||
|
||||
---@param platform string
|
||||
---@param contests table[]
|
||||
function M.set_contest_list(platform, contests)
|
||||
vim.validate({
|
||||
platform = { platform, 'string' },
|
||||
contests = { contests, 'table' },
|
||||
})
|
||||
|
||||
if not cache_data.contest_lists then
|
||||
cache_data.contest_lists = {}
|
||||
end
|
||||
|
||||
local ttl = CONTEST_LIST_TTL[platform] or (24 * 60 * 60) -- Default 1 day
|
||||
cache_data.contest_lists[platform] = {
|
||||
contests = contests,
|
||||
cached_at = os.time(),
|
||||
expires_at = os.time() + ttl,
|
||||
}
|
||||
|
||||
M.save()
|
||||
end
|
||||
|
||||
---@param platform string
|
||||
function M.clear_contest_list(platform)
|
||||
vim.validate({
|
||||
platform = { platform, 'string' },
|
||||
})
|
||||
|
||||
if cache_data.contest_lists and cache_data.contest_lists[platform] then
|
||||
cache_data.contest_lists[platform] = nil
|
||||
M.save()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -708,7 +708,7 @@ local function handle_pick_action()
|
|||
end
|
||||
|
||||
if config.picker == 'telescope' then
|
||||
local ok, telescope = pcall(require, 'telescope')
|
||||
local ok = pcall(require, 'telescope')
|
||||
if not ok then
|
||||
logger.log(
|
||||
'Telescope not available. Install telescope.nvim or change picker config',
|
||||
|
|
|
|||
|
|
@ -37,6 +37,12 @@ end
|
|||
local function get_contests_for_platform(platform)
|
||||
local contests = {}
|
||||
|
||||
cache.load()
|
||||
local cached_contests = cache.get_contest_list(platform)
|
||||
if cached_contests then
|
||||
return cached_contests
|
||||
end
|
||||
|
||||
if not utils.setup_python_env() then
|
||||
return contests
|
||||
end
|
||||
|
|
@ -81,6 +87,7 @@ local function get_contests_for_platform(platform)
|
|||
})
|
||||
end
|
||||
|
||||
cache.set_contest_list(platform, contests)
|
||||
return contests
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,29 @@
|
|||
local finders = require('telescope.finders')
|
||||
local pickers = require('telescope.pickers')
|
||||
local telescope = require('telescope')
|
||||
local conf = require('telescope.config').values
|
||||
local action_state = require('telescope.actions.state')
|
||||
local actions = require('telescope.actions')
|
||||
|
||||
local picker_utils = require('cp.pickers')
|
||||
|
||||
local function platform_picker(opts)
|
||||
opts = opts or {}
|
||||
local function problem_picker(opts, platform, contest_id)
|
||||
local constants = require('cp.constants')
|
||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
local problems = picker_utils.get_problems_for_contest(platform, contest_id)
|
||||
|
||||
local platforms = picker_utils.get_platforms()
|
||||
if #problems == 0 then
|
||||
vim.notify(
|
||||
('No problems found for contest: %s %s'):format(platform_display_name, contest_id),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
pickers
|
||||
.new(opts, {
|
||||
prompt_title = 'Select Platform',
|
||||
prompt_title = ('Select Problem (%s %s)'):format(platform_display_name, contest_id),
|
||||
finder = finders.new_table({
|
||||
results = platforms,
|
||||
results = problems,
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry,
|
||||
|
|
@ -26,13 +33,13 @@ local function platform_picker(opts)
|
|||
end,
|
||||
}),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
|
||||
if selection then
|
||||
contest_picker(opts, selection.value.id)
|
||||
picker_utils.setup_problem(platform, contest_id, selection.value.id)
|
||||
end
|
||||
end)
|
||||
return true
|
||||
|
|
@ -68,7 +75,7 @@ local function contest_picker(opts, platform)
|
|||
end,
|
||||
}),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
|
|
@ -83,24 +90,16 @@ local function contest_picker(opts, platform)
|
|||
:find()
|
||||
end
|
||||
|
||||
local function problem_picker(opts, platform, contest_id)
|
||||
local constants = require('cp.constants')
|
||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||
local problems = picker_utils.get_problems_for_contest(platform, contest_id)
|
||||
local function platform_picker(opts)
|
||||
opts = opts or {}
|
||||
|
||||
if #problems == 0 then
|
||||
vim.notify(
|
||||
('No problems found for contest: %s %s'):format(platform_display_name, contest_id),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
local platforms = picker_utils.get_platforms()
|
||||
|
||||
pickers
|
||||
.new(opts, {
|
||||
prompt_title = ('Select Problem (%s %s)'):format(platform_display_name, contest_id),
|
||||
prompt_title = 'Select Platform',
|
||||
finder = finders.new_table({
|
||||
results = problems,
|
||||
results = platforms,
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry,
|
||||
|
|
@ -110,13 +109,13 @@ local function problem_picker(opts, platform, contest_id)
|
|||
end,
|
||||
}),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
|
||||
if selection then
|
||||
picker_utils.setup_problem(platform, contest_id, selection.value.id)
|
||||
contest_picker(opts, selection.value.id)
|
||||
end
|
||||
end)
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
local M = {}
|
||||
local cache = require('cp.cache')
|
||||
local logger = require('cp.log')
|
||||
local problem = require('cp.problem')
|
||||
local utils = require('cp.utils')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue