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
|
---@class CacheData
|
||||||
---@field [string] table<string, ContestData>
|
---@field [string] table<string, ContestData>
|
||||||
---@field file_states? table<string, FileState>
|
---@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
|
---@class ContestData
|
||||||
---@field problems Problem[]
|
---@field problems Problem[]
|
||||||
|
|
@ -33,6 +39,12 @@ local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json'
|
||||||
local cache_data = {}
|
local cache_data = {}
|
||||||
local loaded = false
|
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
|
---@param platform string
|
||||||
---@return number?
|
---@return number?
|
||||||
local function get_expiry_date(platform)
|
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()
|
M.save()
|
||||||
end
|
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
|
return M
|
||||||
|
|
|
||||||
|
|
@ -708,7 +708,7 @@ local function handle_pick_action()
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.picker == 'telescope' then
|
if config.picker == 'telescope' then
|
||||||
local ok, telescope = pcall(require, 'telescope')
|
local ok = pcall(require, 'telescope')
|
||||||
if not ok then
|
if not ok then
|
||||||
logger.log(
|
logger.log(
|
||||||
'Telescope not available. Install telescope.nvim or change picker config',
|
'Telescope not available. Install telescope.nvim or change picker config',
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,12 @@ end
|
||||||
local function get_contests_for_platform(platform)
|
local function get_contests_for_platform(platform)
|
||||||
local contests = {}
|
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
|
if not utils.setup_python_env() then
|
||||||
return contests
|
return contests
|
||||||
end
|
end
|
||||||
|
|
@ -81,6 +87,7 @@ local function get_contests_for_platform(platform)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cache.set_contest_list(platform, contests)
|
||||||
return contests
|
return contests
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,29 @@
|
||||||
local finders = require('telescope.finders')
|
local finders = require('telescope.finders')
|
||||||
local pickers = require('telescope.pickers')
|
local pickers = require('telescope.pickers')
|
||||||
local telescope = require('telescope')
|
|
||||||
local conf = require('telescope.config').values
|
local conf = require('telescope.config').values
|
||||||
local action_state = require('telescope.actions.state')
|
local action_state = require('telescope.actions.state')
|
||||||
local actions = require('telescope.actions')
|
local actions = require('telescope.actions')
|
||||||
|
|
||||||
local picker_utils = require('cp.pickers')
|
local picker_utils = require('cp.pickers')
|
||||||
|
|
||||||
local function platform_picker(opts)
|
local function problem_picker(opts, platform, contest_id)
|
||||||
opts = opts or {}
|
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
|
pickers
|
||||||
.new(opts, {
|
.new(opts, {
|
||||||
prompt_title = 'Select Platform',
|
prompt_title = ('Select Problem (%s %s)'):format(platform_display_name, contest_id),
|
||||||
finder = finders.new_table({
|
finder = finders.new_table({
|
||||||
results = platforms,
|
results = problems,
|
||||||
entry_maker = function(entry)
|
entry_maker = function(entry)
|
||||||
return {
|
return {
|
||||||
value = entry,
|
value = entry,
|
||||||
|
|
@ -26,13 +33,13 @@ local function platform_picker(opts)
|
||||||
end,
|
end,
|
||||||
}),
|
}),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
attach_mappings = function(prompt_bufnr)
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
if selection then
|
if selection then
|
||||||
contest_picker(opts, selection.value.id)
|
picker_utils.setup_problem(platform, contest_id, selection.value.id)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
|
|
@ -68,7 +75,7 @@ local function contest_picker(opts, platform)
|
||||||
end,
|
end,
|
||||||
}),
|
}),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
attach_mappings = function(prompt_bufnr)
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
@ -83,24 +90,16 @@ local function contest_picker(opts, platform)
|
||||||
:find()
|
:find()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function problem_picker(opts, platform, contest_id)
|
local function platform_picker(opts)
|
||||||
local constants = require('cp.constants')
|
opts = opts or {}
|
||||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
|
||||||
local problems = picker_utils.get_problems_for_contest(platform, contest_id)
|
|
||||||
|
|
||||||
if #problems == 0 then
|
local platforms = picker_utils.get_platforms()
|
||||||
vim.notify(
|
|
||||||
('No problems found for contest: %s %s'):format(platform_display_name, contest_id),
|
|
||||||
vim.log.levels.WARN
|
|
||||||
)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
pickers
|
pickers
|
||||||
.new(opts, {
|
.new(opts, {
|
||||||
prompt_title = ('Select Problem (%s %s)'):format(platform_display_name, contest_id),
|
prompt_title = 'Select Platform',
|
||||||
finder = finders.new_table({
|
finder = finders.new_table({
|
||||||
results = problems,
|
results = platforms,
|
||||||
entry_maker = function(entry)
|
entry_maker = function(entry)
|
||||||
return {
|
return {
|
||||||
value = entry,
|
value = entry,
|
||||||
|
|
@ -110,13 +109,13 @@ local function problem_picker(opts, platform, contest_id)
|
||||||
end,
|
end,
|
||||||
}),
|
}),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
attach_mappings = function(prompt_bufnr)
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
if selection then
|
if selection then
|
||||||
picker_utils.setup_problem(platform, contest_id, selection.value.id)
|
contest_picker(opts, selection.value.id)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
local cache = require('cp.cache')
|
local cache = require('cp.cache')
|
||||||
local logger = require('cp.log')
|
|
||||||
local problem = require('cp.problem')
|
local problem = require('cp.problem')
|
||||||
local utils = require('cp.utils')
|
local utils = require('cp.utils')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ describe('cp.fzf_lua', function()
|
||||||
|
|
||||||
package.preload['fzf-lua'] = function()
|
package.preload['fzf-lua'] = function()
|
||||||
return {
|
return {
|
||||||
fzf_exec = function(entries, opts) end,
|
fzf_exec = function() end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue