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

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

View file

@ -286,11 +286,6 @@ end
---@param problem_id? string
---@return string
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
return (contest_id .. problem_id):lower()
else

View file

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

View file

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

View file

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