fix docs and superfluous vim.validate calls

This commit is contained in:
Barrett Ruth 2025-09-30 20:55:29 -04:00
parent b5b2c770fc
commit 46cd509747
6 changed files with 12 additions and 102 deletions

View file

@ -364,29 +364,18 @@ Example: Setting up and solving AtCoder contest ABC324
PICKER INTEGRATION *cp-picker* PICKER INTEGRATION *cp-picker*
When picker integration is enabled in configuration, cp.nvim provides interactive When picker integration is enabled in configuration, cp.nvim provides interactive
platform, contest, and problem selection using telescope.nvim or fzf-lua. platform and contest selection using telescope.nvim or fzf-lua.
:CP pick *:CP-pick* :CP pick *:CP-pick*
Launch configured picker for interactive problem selection. Launch configured picker for interactive problem selection.
Control Flow: Select Platform → Contest → Problem → Code! Control Flow: Select Platform → Contest → Code!
Requires picker = 'telescope' or picker = 'fzf-lua' in configuration. Requires picker = 'telescope' or picker = 'fzf-lua' in configuration.
Requires corresponding plugin (telescope.nvim or fzf-lua) to be installed. Requires corresponding plugin (telescope.nvim or fzf-lua) to be installed.
Picker Controls ~ PICKER KEYMAPS *cp-picker-keys*
*cp-picker-controls* <c-r> Force refresh contest list, bypassing cache.
The picker interface provides several keyboard shortcuts for enhanced control:
<c-r> Force refresh contest list, bypassing cache
Useful when contest lists are outdated or incomplete Useful when contest lists are outdated or incomplete
Shows loading indicator during refresh operation
Standard picker controls (telescope.nvim/fzf-lua):
<cr> Select current item and proceed to next step
<c-c> / <esc> Cancel picker and return to editor
<c-n> / <down> Navigate to next item
<c-p> / <up> Navigate to previous item
/ Start filtering/searching items
============================================================================== ==============================================================================
RUN PANEL *cp-run* RUN PANEL *cp-run*

View file

@ -227,10 +227,6 @@ end
---@param file_path string ---@param file_path string
---@return FileState? ---@return FileState?
function M.get_file_state(file_path) function M.get_file_state(file_path)
vim.validate({
file_path = { file_path, 'string' },
})
if not cache_data.file_states then if not cache_data.file_states then
return nil return nil
end end
@ -244,18 +240,6 @@ end
---@param problem_id? string ---@param problem_id? string
---@param language? string ---@param language? string
function M.set_file_state(file_path, platform, contest_id, problem_id, language) function M.set_file_state(file_path, platform, contest_id, problem_id, language)
vim.validate({
file_path = { file_path, 'string' },
platform = { platform, 'string' },
contest_id = { contest_id, 'string' },
problem_id = { problem_id, { 'string', 'nil' }, true },
language = { language, { 'string', 'nil' }, true },
})
if not cache_data.file_states then
cache_data.file_states = {}
end
cache_data.file_states[file_path] = { cache_data.file_states[file_path] = {
platform = platform, platform = platform,
contest_id = contest_id, contest_id = contest_id,
@ -269,10 +253,6 @@ end
---@param platform string ---@param platform string
---@return table[]? ---@return table[]?
function M.get_contest_list(platform) function M.get_contest_list(platform)
vim.validate({
platform = { platform, 'string' },
})
if not cache_data.contest_lists or not cache_data.contest_lists[platform] then if not cache_data.contest_lists or not cache_data.contest_lists[platform] then
return nil return nil
end end
@ -283,11 +263,6 @@ end
---@param platform string ---@param platform string
---@param contests table[] ---@param contests table[]
function M.set_contest_list(platform, contests) function M.set_contest_list(platform, contests)
vim.validate({
platform = { platform, 'string' },
contests = { contests, 'table' },
})
if not cache_data.contest_lists then if not cache_data.contest_lists then
cache_data.contest_lists = {} cache_data.contest_lists = {}
end end
@ -302,10 +277,6 @@ end
---@param platform string ---@param platform string
function M.clear_contest_list(platform) function M.clear_contest_list(platform)
vim.validate({
platform = { platform, 'string' },
})
if cache_data.contest_lists and cache_data.contest_lists[platform] then if cache_data.contest_lists and cache_data.contest_lists[platform] then
cache_data.contest_lists[platform] = nil cache_data.contest_lists[platform] = nil
M.save() M.save()
@ -319,10 +290,6 @@ end
---@param platform string ---@param platform string
function M.clear_platform(platform) function M.clear_platform(platform)
vim.validate({
platform = { platform, 'string' },
})
if cache_data[platform] then if cache_data[platform] then
cache_data[platform] = nil cache_data[platform] = nil
end end

View file

@ -286,11 +286,6 @@ end
---@param problem_id? string ---@param problem_id? string
---@return string ---@return string
local function default_filename(contest_id, problem_id) local function default_filename(contest_id, problem_id)
vim.validate({
contest_id = { contest_id, 'string' },
problem_id = { problem_id, { 'string', 'nil' }, true },
})
if problem_id then if problem_id then
return (contest_id .. problem_id):lower() return (contest_id .. problem_id):lower()
else else

View file

@ -108,7 +108,6 @@ function M.get_contests_for_platform(platform)
}) })
end end
cache.set_contest_list(platform, contests)
logger.log(('loaded %d contests'):format(#contests)) logger.log(('loaded %d contests'):format(#contests))
return contests return contests
end end

View file

@ -47,7 +47,7 @@ local function contest_picker(opts, platform)
end end
end) end)
map('i', '<C-r>', function() map('i', '<c-r>', function()
local cache = require('cp.cache') local cache = require('cp.cache')
cache.clear_contest_list(platform) cache.clear_contest_list(platform)
actions.close(prompt_bufnr) actions.close(prompt_bufnr)

View file

@ -15,11 +15,6 @@ local filetype_to_language = constants.filetype_to_language
---@param contest_config table ---@param contest_config table
---@return string ---@return string
local function get_language_from_file(source_file, contest_config) local function get_language_from_file(source_file, contest_config)
vim.validate({
source_file = { source_file, 'string' },
contest_config = { contest_config, 'table' },
})
local extension = vim.fn.fnamemodify(source_file, ':e') local extension = vim.fn.fnamemodify(source_file, ':e')
local language = filetype_to_language[extension] or contest_config.default_language local language = filetype_to_language[extension] or contest_config.default_language
return language return language
@ -29,11 +24,6 @@ end
---@param substitutions table<string, string> ---@param substitutions table<string, string>
---@return string[] ---@return string[]
local function substitute_template(cmd_template, substitutions) local function substitute_template(cmd_template, substitutions)
vim.validate({
cmd_template = { cmd_template, 'table' },
substitutions = { substitutions, 'table' },
})
local result = {} local result = {}
for _, arg in ipairs(cmd_template) do for _, arg in ipairs(cmd_template) do
local substituted = arg local substituted = arg
@ -50,12 +40,6 @@ end
---@param substitutions table<string, string> ---@param substitutions table<string, string>
---@return string[] ---@return string[]
local function build_command(cmd_template, executable, substitutions) local function build_command(cmd_template, executable, substitutions)
vim.validate({
cmd_template = { cmd_template, 'table' },
executable = { executable, { 'string', 'nil' }, true },
substitutions = { substitutions, 'table' },
})
local cmd = substitute_template(cmd_template, substitutions) local cmd = substitute_template(cmd_template, substitutions)
if executable then if executable then
table.insert(cmd, 1, executable) table.insert(cmd, 1, executable)
@ -67,11 +51,6 @@ end
---@param substitutions table<string, string> ---@param substitutions table<string, string>
---@return {code: integer, stdout: string, stderr: string} ---@return {code: integer, stdout: string, stderr: string}
function M.compile_generic(language_config, substitutions) function M.compile_generic(language_config, substitutions)
vim.validate({
language_config = { language_config, 'table' },
substitutions = { substitutions, 'table' },
})
if not language_config.compile then if not language_config.compile then
logger.log('no compilation step required') logger.log('no compilation step required')
return { code = 0, stderr = '' } return { code = 0, stderr = '' }
@ -107,12 +86,6 @@ end
---@param timeout_ms number ---@param timeout_ms number
---@return ExecuteResult ---@return ExecuteResult
local function execute_command(cmd, input_data, timeout_ms) local function execute_command(cmd, input_data, timeout_ms)
vim.validate({
cmd = { cmd, 'table' },
input_data = { input_data, 'string' },
timeout_ms = { timeout_ms, 'number' },
})
local redirected_cmd = vim.deepcopy(cmd) local redirected_cmd = vim.deepcopy(cmd)
if #redirected_cmd > 0 then if #redirected_cmd > 0 then
redirected_cmd[#redirected_cmd] = redirected_cmd[#redirected_cmd] .. ' 2>&1' redirected_cmd[#redirected_cmd] = redirected_cmd[#redirected_cmd] .. ' 2>&1'
@ -158,12 +131,6 @@ end
---@param is_debug boolean ---@param is_debug boolean
---@return string ---@return string
local function format_output(exec_result, expected_file, is_debug) local function format_output(exec_result, expected_file, is_debug)
vim.validate({
exec_result = { exec_result, 'table' },
expected_file = { expected_file, 'string' },
is_debug = { is_debug, 'boolean' },
})
local output_lines = { exec_result.stdout } local output_lines = { exec_result.stdout }
local metadata_lines = {} local metadata_lines = {}
@ -207,10 +174,6 @@ end
---@param is_debug? boolean ---@param is_debug? boolean
---@return {success: boolean, output: string?} ---@return {success: boolean, output: string?}
function M.compile_problem(contest_config, is_debug) function M.compile_problem(contest_config, is_debug)
vim.validate({
contest_config = { contest_config, 'table' },
})
local state = require('cp.state') local state = require('cp.state')
local source_file = state.get_source_file() local source_file = state.get_source_file()
if not source_file then if not source_file then
@ -249,12 +212,9 @@ function M.compile_problem(contest_config, is_debug)
return { success = true, output = nil } return { success = true, output = nil }
end end
---@param contest_config ContestConfig
---@param is_debug boolean
function M.run_problem(contest_config, is_debug) function M.run_problem(contest_config, is_debug)
vim.validate({
contest_config = { contest_config, 'table' },
is_debug = { is_debug, 'boolean' },
})
local state = require('cp.state') local state = require('cp.state')
local source_file = state.get_source_file() local source_file = state.get_source_file()
local output_file = state.get_output_file() local output_file = state.get_output_file()