feat: start lang refactor

This commit is contained in:
Barrett Ruth 2025-10-24 01:11:19 -04:00
parent ce12ab0e1a
commit bd30fb626c
7 changed files with 229 additions and 45 deletions

View file

@ -2,7 +2,7 @@ local picker_utils = require('cp.pickers')
local M = {}
local function contest_picker(platform, refresh)
local function contest_picker(platform, refresh, language)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform]
local fzf = require('fzf-lua')
@ -42,19 +42,24 @@ local function contest_picker(platform, refresh)
if contest then
local cp = require('cp')
cp.handle_command({ fargs = { platform, contest.id } })
local fargs = { platform, contest.id }
if language then
table.insert(fargs, '--lang')
table.insert(fargs, language)
end
cp.handle_command({ fargs = fargs })
end
end,
['ctrl-r'] = function()
local cache = require('cp.cache')
cache.clear_contest_list(platform)
contest_picker(platform, true)
contest_picker(platform, true, language)
end,
},
})
end
function M.pick()
function M.pick(language)
local fzf = require('fzf-lua')
local platforms = picker_utils.get_platforms()
local entries = vim.tbl_map(function(platform)
@ -79,7 +84,7 @@ function M.pick()
end
if platform then
contest_picker(platform.id)
contest_picker(platform.id, false, language)
end
end,
},

View file

@ -8,7 +8,7 @@ local picker_utils = require('cp.pickers')
local M = {}
local function contest_picker(opts, platform, refresh)
local function contest_picker(opts, platform, refresh, language)
local constants = require('cp.constants')
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform]
local contests = picker_utils.get_platform_contests(platform, refresh)
@ -43,13 +43,18 @@ local function contest_picker(opts, platform, refresh)
if selection then
local cp = require('cp')
cp.handle_command({ fargs = { platform, selection.value.id } })
local fargs = { platform, selection.value.id }
if language then
table.insert(fargs, '--lang')
table.insert(fargs, language)
end
cp.handle_command({ fargs = fargs })
end
end)
map('i', '<c-r>', function()
actions.close(prompt_bufnr)
contest_picker(opts, platform, true)
contest_picker(opts, platform, true, language)
end)
return true
@ -58,9 +63,8 @@ local function contest_picker(opts, platform, refresh)
:find()
end
function M.pick(opts)
opts = opts or {}
function M.pick(language)
local opts = {}
local platforms = picker_utils.get_platforms()
pickers
@ -83,7 +87,7 @@ function M.pick(opts)
actions.close(prompt_bufnr)
if selection then
contest_picker(opts, selection.value.id)
contest_picker(opts, selection.value.id, false, language)
end
end)
return true