docs(lua): add LuaCATS type annotations across core modules
This commit is contained in:
parent
fc2331c242
commit
1f0414de8e
15 changed files with 73 additions and 0 deletions
|
|
@ -266,6 +266,7 @@ end
|
||||||
---@param memory_mb number
|
---@param memory_mb number
|
||||||
---@param interactive boolean
|
---@param interactive boolean
|
||||||
---@param multi_test boolean
|
---@param multi_test boolean
|
||||||
|
---@param precision number?
|
||||||
function M.set_test_cases(
|
function M.set_test_cases(
|
||||||
platform,
|
platform,
|
||||||
contest_id,
|
contest_id,
|
||||||
|
|
@ -467,6 +468,7 @@ function M.clear_credentials(platform)
|
||||||
M.save()
|
M.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.clear_all()
|
function M.clear_all()
|
||||||
cache_data = {}
|
cache_data = {}
|
||||||
M.save()
|
M.save()
|
||||||
|
|
@ -488,6 +490,7 @@ function M.get_data_pretty()
|
||||||
return vim.inspect(cache_data)
|
return vim.inspect(cache_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return table
|
||||||
function M.get_raw_cache()
|
function M.get_raw_cache()
|
||||||
return cache_data
|
return cache_data
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -531,10 +531,12 @@ end
|
||||||
|
|
||||||
local current_config = nil
|
local current_config = nil
|
||||||
|
|
||||||
|
---@param config cp.Config
|
||||||
function M.set_current_config(config)
|
function M.set_current_config(config)
|
||||||
current_config = config
|
current_config = config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return cp.Config
|
||||||
function M.get_config()
|
function M.get_config()
|
||||||
return current_config or M.defaults
|
return current_config or M.defaults
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ local STATUS_MESSAGES = {
|
||||||
installing_browser = 'Installing browser...',
|
installing_browser = 'Installing browser...',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@param platform string?
|
||||||
function M.login(platform)
|
function M.login(platform)
|
||||||
platform = platform or state.get_platform()
|
platform = platform or state.get_platform()
|
||||||
if not platform then
|
if not platform then
|
||||||
|
|
@ -68,6 +69,7 @@ function M.login(platform)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param platform string?
|
||||||
function M.logout(platform)
|
function M.logout(platform)
|
||||||
platform = platform or state.get_platform()
|
platform = platform or state.get_platform()
|
||||||
if not platform then
|
if not platform then
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ local function check()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.check()
|
function M.check()
|
||||||
local version = require('cp.version')
|
local version = require('cp.version')
|
||||||
vim.health.start('cp.nvim health check ~')
|
vim.health.start('cp.nvim health check ~')
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,13 @@ function M.handle_command(opts)
|
||||||
commands.handle_command(opts)
|
commands.handle_command(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
function M.is_initialized()
|
function M.is_initialized()
|
||||||
return initialized
|
return initialized
|
||||||
end
|
end
|
||||||
|
|
||||||
---@deprecated Use `vim.g.cp` instead
|
---@deprecated Use `vim.g.cp` instead
|
||||||
|
---@param user_config table?
|
||||||
function M.setup(user_config)
|
function M.setup(user_config)
|
||||||
vim.deprecate('require("cp").setup()', 'vim.g.cp', 'v0.7.7', 'cp.nvim', false)
|
vim.deprecate('require("cp").setup()', 'vim.g.cp', 'v0.7.7', 'cp.nvim', false)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,9 @@ local function race_try_setup(platform, contest_id, language, attempt, token)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param platform string
|
||||||
|
---@param contest_id string
|
||||||
|
---@param language? string
|
||||||
function M.start(platform, contest_id, language)
|
function M.start(platform, contest_id, language)
|
||||||
if not platform or not vim.tbl_contains(constants.PLATFORMS, platform) then
|
if not platform or not vim.tbl_contains(constants.PLATFORMS, platform) then
|
||||||
logger.log('Invalid platform', { level = vim.log.levels.ERROR })
|
logger.log('Invalid platform', { level = vim.log.levels.ERROR })
|
||||||
|
|
@ -252,6 +255,7 @@ function M.start(platform, contest_id, language)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.stop()
|
function M.stop()
|
||||||
local timer = race_state.timer
|
local timer = race_state.timer
|
||||||
if not timer then
|
if not timer then
|
||||||
|
|
@ -276,6 +280,7 @@ function M.stop()
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return { active: boolean, platform?: string, contest_id?: string, remaining_seconds?: integer }
|
||||||
function M.status()
|
function M.status()
|
||||||
if not race_state.timer or not race_state.start_time then
|
if not race_state.timer or not race_state.start_time then
|
||||||
return { active = false }
|
return { active = false }
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ local function substitute_template(cmd_template, substitutions)
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param cmd_template string[]
|
||||||
|
---@param substitutions SubstitutableCommand
|
||||||
|
---@return string[]
|
||||||
function M.build_command(cmd_template, substitutions)
|
function M.build_command(cmd_template, substitutions)
|
||||||
return substitute_template(cmd_template, substitutions)
|
return substitute_template(cmd_template, substitutions)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -376,6 +376,7 @@ function M.get_highlight_groups()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.setup_highlights()
|
function M.setup_highlights()
|
||||||
local groups = M.get_highlight_groups()
|
local groups = M.get_highlight_groups()
|
||||||
for name, opts in pairs(groups) do
|
for name, opts in pairs(groups) do
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,10 @@ local function run_scraper(platform, subcommand, args, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param platform string
|
||||||
|
---@param contest_id string
|
||||||
|
---@param callback fun(data: table)?
|
||||||
|
---@param on_error fun()?
|
||||||
function M.scrape_contest_metadata(platform, contest_id, callback, on_error)
|
function M.scrape_contest_metadata(platform, contest_id, callback, on_error)
|
||||||
run_scraper(platform, 'metadata', { contest_id }, {
|
run_scraper(platform, 'metadata', { contest_id }, {
|
||||||
on_exit = function(result)
|
on_exit = function(result)
|
||||||
|
|
@ -253,6 +257,8 @@ function M.scrape_contest_metadata(platform, contest_id, callback, on_error)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param platform string
|
||||||
|
---@return { contests: ContestSummary[], supports_countdown: boolean }?
|
||||||
function M.scrape_contest_list(platform)
|
function M.scrape_contest_list(platform)
|
||||||
local result = run_scraper(platform, 'contests', {}, { sync = true })
|
local result = run_scraper(platform, 'contests', {}, { sync = true })
|
||||||
if not result or not result.success or not (result.data and result.data.contests) then
|
if not result or not result.success or not (result.data and result.data.contests) then
|
||||||
|
|
@ -330,6 +336,10 @@ function M.scrape_all_tests(platform, contest_id, callback, on_done)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param platform string
|
||||||
|
---@param credentials table
|
||||||
|
---@param on_status fun(ev: table)?
|
||||||
|
---@param callback fun(result: table)?
|
||||||
function M.login(platform, credentials, on_status, callback)
|
function M.login(platform, credentials, on_status, callback)
|
||||||
local done = false
|
local done = false
|
||||||
run_scraper(platform, 'login', {}, {
|
run_scraper(platform, 'login', {}, {
|
||||||
|
|
@ -361,6 +371,14 @@ function M.login(platform, credentials, on_status, callback)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param platform string
|
||||||
|
---@param contest_id string
|
||||||
|
---@param problem_id string
|
||||||
|
---@param language string
|
||||||
|
---@param source_file string
|
||||||
|
---@param credentials table
|
||||||
|
---@param on_status fun(ev: table)?
|
||||||
|
---@param callback fun(result: table)?
|
||||||
function M.submit(
|
function M.submit(
|
||||||
platform,
|
platform,
|
||||||
contest_id,
|
contest_id,
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ local function build_run_cmd(file)
|
||||||
return './' .. file
|
return './' .. file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param generator_cmd? string
|
||||||
|
---@param brute_cmd? string
|
||||||
function M.toggle(generator_cmd, brute_cmd)
|
function M.toggle(generator_cmd, brute_cmd)
|
||||||
if state.get_active_panel() == 'stress' then
|
if state.get_active_panel() == 'stress' then
|
||||||
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
|
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
|
||||||
|
|
@ -239,6 +241,7 @@ function M.toggle(generator_cmd, brute_cmd)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.cancel()
|
function M.cancel()
|
||||||
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
|
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
|
||||||
local job = vim.b[state.stress_buf].terminal_job_id
|
local job = vim.b[state.stress_buf].terminal_job_id
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ local function prompt_credentials(platform, callback)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param opts { language?: string }?
|
||||||
function M.submit(opts)
|
function M.submit(opts)
|
||||||
local platform = state.get_platform()
|
local platform = state.get_platform()
|
||||||
local contest_id = state.get_contest_id()
|
local contest_id = state.get_contest_id()
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,7 @@ setup_keybindings = function(buf)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param test_index? integer
|
||||||
function M.toggle_edit(test_index)
|
function M.toggle_edit(test_index)
|
||||||
if edit_state then
|
if edit_state then
|
||||||
save_all_tests()
|
save_all_tests()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
---@class DiffLayout
|
||||||
|
---@field buffers integer[]
|
||||||
|
---@field windows integer[]
|
||||||
|
---@field mode string
|
||||||
|
---@field cleanup fun()
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local helpers = require('cp.helpers')
|
local helpers = require('cp.helpers')
|
||||||
|
|
@ -171,6 +177,11 @@ local function create_single_layout(parent_win, content)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param mode string
|
||||||
|
---@param parent_win integer
|
||||||
|
---@param expected_content string
|
||||||
|
---@param actual_content string
|
||||||
|
---@return DiffLayout
|
||||||
function M.create_diff_layout(mode, parent_win, expected_content, actual_content)
|
function M.create_diff_layout(mode, parent_win, expected_content, actual_content)
|
||||||
if mode == 'single' then
|
if mode == 'single' then
|
||||||
return create_single_layout(parent_win, actual_content)
|
return create_single_layout(parent_win, actual_content)
|
||||||
|
|
@ -185,6 +196,13 @@ function M.create_diff_layout(mode, parent_win, expected_content, actual_content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param current_diff_layout DiffLayout?
|
||||||
|
---@param current_mode string?
|
||||||
|
---@param main_win integer
|
||||||
|
---@param run table
|
||||||
|
---@param config cp.Config
|
||||||
|
---@param setup_keybindings_for_buffer fun(buf: integer)
|
||||||
|
---@return DiffLayout?, string?
|
||||||
function M.update_diff_panes(
|
function M.update_diff_panes(
|
||||||
current_diff_layout,
|
current_diff_layout,
|
||||||
current_mode,
|
current_mode,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ local current_diff_layout = nil
|
||||||
local current_mode = nil
|
local current_mode = nil
|
||||||
local _run_gen = 0
|
local _run_gen = 0
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.disable()
|
function M.disable()
|
||||||
local active_panel = state.get_active_panel()
|
local active_panel = state.get_active_panel()
|
||||||
if not active_panel then
|
if not active_panel then
|
||||||
|
|
@ -351,6 +352,7 @@ local function create_window_layout(output_buf, input_buf)
|
||||||
vim.api.nvim_set_current_win(solution_win)
|
vim.api.nvim_set_current_win(solution_win)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.ensure_io_view()
|
function M.ensure_io_view()
|
||||||
local platform, contest_id, problem_id =
|
local platform, contest_id, problem_id =
|
||||||
state.get_platform(), state.get_contest_id(), state.get_problem_id()
|
state.get_platform(), state.get_contest_id(), state.get_problem_id()
|
||||||
|
|
@ -598,6 +600,9 @@ local function render_io_view_results(io_state, test_indices, mode, combined_res
|
||||||
utils.update_buffer_content(io_state.output_buf, output_lines, final_highlights, output_ns)
|
utils.update_buffer_content(io_state.output_buf, output_lines, final_highlights, output_ns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param test_indices_arg integer[]?
|
||||||
|
---@param debug boolean?
|
||||||
|
---@param mode? string
|
||||||
function M.run_io_view(test_indices_arg, debug, mode)
|
function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
_run_gen = _run_gen + 1
|
_run_gen = _run_gen + 1
|
||||||
local gen = _run_gen
|
local gen = _run_gen
|
||||||
|
|
@ -754,10 +759,12 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.cancel_io_view()
|
function M.cancel_io_view()
|
||||||
_run_gen = _run_gen + 1
|
_run_gen = _run_gen + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.cancel_interactive()
|
function M.cancel_interactive()
|
||||||
if state.interactive_buf and vim.api.nvim_buf_is_valid(state.interactive_buf) then
|
if state.interactive_buf and vim.api.nvim_buf_is_valid(state.interactive_buf) then
|
||||||
local job = vim.b[state.interactive_buf].terminal_job_id
|
local job = vim.b[state.interactive_buf].terminal_job_id
|
||||||
|
|
|
||||||
|
|
@ -314,6 +314,7 @@ end
|
||||||
|
|
||||||
--- Configure the buffer with good defaults
|
--- Configure the buffer with good defaults
|
||||||
---@param filetype? string
|
---@param filetype? string
|
||||||
|
---@return integer
|
||||||
function M.create_buffer_with_options(filetype)
|
function M.create_buffer_with_options(filetype)
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
vim.api.nvim_set_option_value('bufhidden', 'hide', { buf = buf })
|
vim.api.nvim_set_option_value('bufhidden', 'hide', { buf = buf })
|
||||||
|
|
@ -345,6 +346,7 @@ function M.update_buffer_content(bufnr, lines, highlights, namespace)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return boolean, string?
|
||||||
function M.check_required_runtime()
|
function M.check_required_runtime()
|
||||||
if is_windows() then
|
if is_windows() then
|
||||||
return false, 'Windows is not supported'
|
return false, 'Windows is not supported'
|
||||||
|
|
@ -419,16 +421,19 @@ local function find_gnu_timeout()
|
||||||
return _timeout_path, _timeout_reason
|
return _timeout_path, _timeout_reason
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return string?
|
||||||
function M.timeout_path()
|
function M.timeout_path()
|
||||||
local path = find_gnu_timeout()
|
local path = find_gnu_timeout()
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return { ok: boolean, path: string|nil, reason: string|nil }
|
||||||
function M.timeout_capability()
|
function M.timeout_capability()
|
||||||
local path, reason = find_gnu_timeout()
|
local path, reason = find_gnu_timeout()
|
||||||
return { ok = path ~= nil, path = path, reason = reason }
|
return { ok = path ~= nil, path = path, reason = reason }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return string[]
|
||||||
function M.cwd_executables()
|
function M.cwd_executables()
|
||||||
local uv = vim.uv
|
local uv = vim.uv
|
||||||
local req = uv.fs_scandir('.')
|
local req = uv.fs_scandir('.')
|
||||||
|
|
@ -452,6 +457,7 @@ function M.cwd_executables()
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function M.ensure_dirs()
|
function M.ensure_dirs()
|
||||||
vim.system({ 'mkdir', '-p', 'build', 'io' }):wait()
|
vim.system({ 'mkdir', '-p', 'build', 'io' }):wait()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue