fix(picker): rename picker function names
This commit is contained in:
parent
a7cd41712d
commit
5588eae526
5 changed files with 27 additions and 118 deletions
|
|
@ -14,6 +14,8 @@ function M.handle_pick_action()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local picker
|
||||||
|
|
||||||
if config.picker == 'telescope' then
|
if config.picker == 'telescope' then
|
||||||
local ok = pcall(require, 'telescope')
|
local ok = pcall(require, 'telescope')
|
||||||
if not ok then
|
if not ok then
|
||||||
|
|
@ -23,12 +25,13 @@ function M.handle_pick_action()
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
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
|
if not ok_cp then
|
||||||
logger.log('Failed to load telescope integration', vim.log.levels.ERROR)
|
logger.log('Failed to load telescope integration', vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
telescope_cp.platform_picker()
|
|
||||||
|
picker = telescope_picker
|
||||||
elseif config.picker == 'fzf-lua' then
|
elseif config.picker == 'fzf-lua' then
|
||||||
local ok, _ = pcall(require, 'fzf-lua')
|
local ok, _ = pcall(require, 'fzf-lua')
|
||||||
if not ok then
|
if not ok then
|
||||||
|
|
@ -38,13 +41,16 @@ function M.handle_pick_action()
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
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
|
if not ok_cp then
|
||||||
logger.log('Failed to load fzf-lua integration', vim.log.levels.ERROR)
|
logger.log('Failed to load fzf-lua integration', vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
fzf_cp.platform_picker()
|
|
||||||
|
picker = fzf_picker
|
||||||
end
|
end
|
||||||
|
|
||||||
|
picker.pick()
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
local picker_utils = require('cp.pickers')
|
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 constants = require('cp.constants')
|
||||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||||
local fzf = require('fzf-lua')
|
local fzf = require('fzf-lua')
|
||||||
|
|
@ -41,7 +41,8 @@ function contest_picker(platform)
|
||||||
end
|
end
|
||||||
|
|
||||||
if contest then
|
if contest then
|
||||||
problem_picker(platform, contest.id)
|
local cp = require('cp')
|
||||||
|
cp.handle_command({ fargs = { platform, contest.id } })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
['ctrl-r'] = function()
|
['ctrl-r'] = function()
|
||||||
|
|
@ -53,55 +54,7 @@ function contest_picker(platform)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function problem_picker(platform, contest_id)
|
function M.picker()
|
||||||
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()
|
|
||||||
local fzf = require('fzf-lua')
|
local fzf = require('fzf-lua')
|
||||||
local platforms = picker_utils.get_platforms()
|
local platforms = picker_utils.get_platforms()
|
||||||
local entries = vim.tbl_map(function(platform)
|
local entries = vim.tbl_map(function(platform)
|
||||||
|
|
@ -133,6 +86,4 @@ local function platform_picker()
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return M
|
||||||
platform_picker = platform_picker,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ local actions = require('telescope.actions')
|
||||||
|
|
||||||
local picker_utils = require('cp.pickers')
|
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 constants = require('cp.constants')
|
||||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
||||||
local contests = picker_utils.get_contests_for_platform(platform)
|
local contests = picker_utils.get_contests_for_platform(platform)
|
||||||
|
|
@ -24,7 +24,7 @@ function contest_picker(opts, platform)
|
||||||
pickers
|
pickers
|
||||||
.new(opts, {
|
.new(opts, {
|
||||||
prompt_title = ('Select Contest (%s)'):format(platform_display_name),
|
prompt_title = ('Select Contest (%s)'):format(platform_display_name),
|
||||||
results_title = '<C-r> refresh',
|
results_title = '<c-r> refresh',
|
||||||
finder = finders.new_table({
|
finder = finders.new_table({
|
||||||
results = contests,
|
results = contests,
|
||||||
entry_maker = function(entry)
|
entry_maker = function(entry)
|
||||||
|
|
@ -42,7 +42,8 @@ function contest_picker(opts, platform)
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
if selection then
|
if selection then
|
||||||
problem_picker(opts, platform, selection.value.id)
|
local cp = require('cp')
|
||||||
|
cp.handle_command({ fargs = { platform, selection.value.id } })
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -59,54 +60,7 @@ function contest_picker(opts, platform)
|
||||||
:find()
|
:find()
|
||||||
end
|
end
|
||||||
|
|
||||||
function problem_picker(opts, platform, contest_id)
|
function M.picker(opts)
|
||||||
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 {}
|
opts = opts or {}
|
||||||
|
|
||||||
local platforms = picker_utils.get_platforms()
|
local platforms = picker_utils.get_platforms()
|
||||||
|
|
@ -140,6 +94,4 @@ local function platform_picker(opts)
|
||||||
:find()
|
:find()
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return M
|
||||||
platform_picker = platform_picker,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,10 @@ describe('cp.fzf_lua', function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns module with platform_picker function', function()
|
it('returns module with picker function', function()
|
||||||
local fzf_lua_cp = require('cp.pickers.fzf_lua')
|
local fzf_lua_cp = require('cp.pickers.fzf_lua')
|
||||||
assert.is_table(fzf_lua_cp)
|
assert.is_table(fzf_lua_cp)
|
||||||
assert.is_function(fzf_lua_cp.platform_picker)
|
assert.is_function(fzf_lua_cp.picker)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,10 @@ describe('cp.telescope', function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns module with platform_picker function', function()
|
it('returns module with picker function', function()
|
||||||
local telescope_cp = require('cp.pickers.telescope')
|
local telescope_cp = require('cp.pickers.telescope')
|
||||||
assert.is_table(telescope_cp)
|
assert.is_table(telescope_cp)
|
||||||
assert.is_function(telescope_cp.platform_picker)
|
assert.is_function(telescope_cp.picker)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue