fix(picker): rename picker function names

This commit is contained in:
Barrett Ruth 2025-09-30 20:27:31 -04:00
parent a7cd41712d
commit 5588eae526
5 changed files with 27 additions and 118 deletions

View file

@ -14,6 +14,8 @@ function M.handle_pick_action()
return
end
local picker
if config.picker == 'telescope' then
local ok = pcall(require, 'telescope')
if not ok then
@ -23,12 +25,13 @@ function M.handle_pick_action()
)
return
end
local ok_cp, telescope_cp = pcall(require, 'cp.pickers.telescope')
local ok_cp, telescope_picker = pcall(require, 'cp.pickers.telescope')
if not ok_cp then
logger.log('Failed to load telescope integration', vim.log.levels.ERROR)
return
end
telescope_cp.platform_picker()
picker = telescope_picker
elseif config.picker == 'fzf-lua' then
local ok, _ = pcall(require, 'fzf-lua')
if not ok then
@ -38,13 +41,16 @@ function M.handle_pick_action()
)
return
end
local ok_cp, fzf_cp = pcall(require, 'cp.pickers.fzf_lua')
local ok_cp, fzf_picker = pcall(require, 'cp.pickers.fzf_lua')
if not ok_cp then
logger.log('Failed to load fzf-lua integration', vim.log.levels.ERROR)
return
end
fzf_cp.platform_picker()
picker = fzf_picker
end
picker.pick()
end
return M

View file

@ -1,8 +1,8 @@
local picker_utils = require('cp.pickers')
local contest_picker, problem_picker
local M
function contest_picker(platform)
local function contest_picker(platform)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
local fzf = require('fzf-lua')
@ -41,7 +41,8 @@ function contest_picker(platform)
end
if contest then
problem_picker(platform, contest.id)
local cp = require('cp')
cp.handle_command({ fargs = { platform, contest.id } })
end
end,
['ctrl-r'] = function()
@ -53,55 +54,7 @@ function contest_picker(platform)
})
end
function problem_picker(platform, contest_id)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
local fzf = require('fzf-lua')
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(platform)
return
end
local entries = vim.tbl_map(function(problem)
return problem.display_name
end, problems)
return fzf.fzf_exec(entries, {
prompt = ('Select Problem (%s %s)> '):format(platform_display_name, contest_id),
actions = {
['default'] = function(selected)
if not selected or #selected == 0 then
return
end
local selected_name = selected[1]
local problem = nil
for _, p in ipairs(problems) do
if p.display_name == selected_name then
problem = p
break
end
end
if problem then
local cp = require('cp')
cp.handle_command({ fargs = { platform, contest_id, problem.id } })
end
end,
},
})
end
local function platform_picker()
function M.picker()
local fzf = require('fzf-lua')
local platforms = picker_utils.get_platforms()
local entries = vim.tbl_map(function(platform)
@ -133,6 +86,4 @@ local function platform_picker()
})
end
return {
platform_picker = platform_picker,
}
return M

View file

@ -6,9 +6,9 @@ local actions = require('telescope.actions')
local picker_utils = require('cp.pickers')
local contest_picker, problem_picker
local M = {}
function contest_picker(opts, platform)
local function contest_picker(opts, platform)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
local contests = picker_utils.get_contests_for_platform(platform)
@ -24,7 +24,7 @@ function contest_picker(opts, platform)
pickers
.new(opts, {
prompt_title = ('Select Contest (%s)'):format(platform_display_name),
results_title = '<C-r> refresh',
results_title = '<c-r> refresh',
finder = finders.new_table({
results = contests,
entry_maker = function(entry)
@ -42,7 +42,8 @@ function contest_picker(opts, platform)
actions.close(prompt_bufnr)
if selection then
problem_picker(opts, platform, selection.value.id)
local cp = require('cp')
cp.handle_command({ fargs = { platform, selection.value.id } })
end
end)
@ -59,54 +60,7 @@ function contest_picker(opts, platform)
:find()
end
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)
function M.picker(opts)
opts = opts or {}
local platforms = picker_utils.get_platforms()
@ -140,6 +94,4 @@ local function platform_picker(opts)
:find()
end
return {
platform_picker = platform_picker,
}
return M