cp.nvim/lua/cp/init.lua
Barrett Ruth 3c11d609f5
feat(codechef): implement full CodeChef support (#354)
## Problem

CodeChef had no working login, submit, or contest list. The browser
selectors were wrong, the contest list was missing present/past
contests,
and problem/contest URLs were unset.

## Solution

Fix login and submit selectors for the Drupal-based site. Paginate
`/api/list/contests/past` to collect all 228 Starters, then expand each
parent contest into individual division entries (e.g. `START228 (Div.
4)`).
Add language IDs, correct `url`/`contest_url`/`standings_url` in
metadata,
and make `:CP <platform>` open the contest picker directly.
2026-03-06 23:10:44 -05:00

56 lines
1.3 KiB
Lua

local M = {}
local config_module = require('cp.config')
local helpers = require('cp.helpers')
local logger = require('cp.log')
M.helpers = helpers
if vim.fn.has('nvim-0.10.0') == 0 then
logger.log('Requires nvim-0.10.0+', { level = vim.log.levels.ERROR })
return {}
end
local initialized = false
local function ensure_initialized()
if initialized then
return true
end
local user_config = vim.g.cp or {}
local ok, result = pcall(config_module.setup, user_config)
if not ok then
local msg = tostring(result):gsub('^.+:%d+: ', '')
logger.log(msg, { level = vim.log.levels.ERROR, override = true, sync = true })
return false
end
config_module.set_current_config(result)
initialized = true
return true
end
---@return nil
function M.handle_command(opts)
if not ensure_initialized() then
return
end
local commands = require('cp.commands')
commands.handle_command(opts)
end
---@return boolean
function M.is_initialized()
return initialized
end
---@deprecated Use `vim.g.cp` instead
---@param user_config table?
function M.setup(user_config)
vim.deprecate('require("cp").setup()', 'vim.g.cp', 'v0.7.7', 'cp.nvim', false)
if user_config then
vim.g.cp = vim.tbl_deep_extend('force', vim.g.cp or {}, user_config)
end
end
return M