This commit is contained in:
Barrett Ruth 2025-09-24 00:44:08 -04:00
parent 7ac91a3c4d
commit 699207e713
4 changed files with 101 additions and 102 deletions

View file

@ -6,53 +6,6 @@ local actions = require('telescope.actions')
local picker_utils = require('cp.pickers')
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)
if #problems == 0 then
vim.notify(
("Contest %s %s hasn't started yet or has no available problems"):format(
platform_display_name,
contest_id
),
vim.log.levels.WARN
)
contest_picker(opts, platform)
return
end
pickers
.new(opts, {
prompt_title = ('Select Problem (%s %s)'):format(platform_display_name, contest_id),
finder = finders.new_table({
results = problems,
entry_maker = function(entry)
return {
value = entry,
display = entry.display_name,
ordinal = entry.display_name,
}
end,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if selection then
local cp = require('cp')
cp.handle_command({ fargs = { platform, contest_id, selection.value.id } })
end
end)
return true
end,
})
:find()
end
local function contest_picker(opts, platform)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
@ -104,6 +57,53 @@ 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)
if #problems == 0 then
vim.notify(
("Contest %s %s hasn't started yet or has no available problems"):format(
platform_display_name,
contest_id
),
vim.log.levels.WARN
)
contest_picker(opts, platform)
return
end
pickers
.new(opts, {
prompt_title = ('Select Problem (%s %s)'):format(platform_display_name, contest_id),
finder = finders.new_table({
results = problems,
entry_maker = function(entry)
return {
value = entry,
display = entry.display_name,
ordinal = entry.display_name,
}
end,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if selection then
local cp = require('cp')
cp.handle_command({ fargs = { platform, contest_id, selection.value.id } })
end
end)
return true
end,
})
:find()
end
local function platform_picker(opts)
opts = opts or {}