config hard fail

This commit is contained in:
Barrett Ruth 2025-10-02 23:20:51 -04:00
parent 69ffc2d9dd
commit cddd61f061
3 changed files with 35 additions and 4 deletions

View file

@ -52,7 +52,10 @@
---@field picker? string|nil
local M = {}
local constants = require('cp.constants')
local logger = require('cp.log')
local utils = require('cp.utils')
local default_contest_config = {
cpp = {
@ -249,6 +252,11 @@ function M.setup(user_config)
end
end
local ok, err = utils.check_required_runtime()
if not ok then
error('[cp.nvim] ' .. err)
end
return config
end

View file

@ -123,7 +123,7 @@ function M.run(cmd, stdin, timeout_ms, memory_mb)
local code = r.code or 0
local raw = r.stdout or ''
local cleaned, peak_mb = parse_and_strip_time_v(raw)
local tled = (code == 124)
local tled = code == 124
local signal = nil
if code >= 128 then

View file

@ -58,9 +58,7 @@ local function find_gnu_time()
return _time_path, _time_reason
end
--- Return the validated GNU time binary path
--- Fails closed: returns nil if GNU time is unavailable.
---@return string|nil path
---@return string|nil path to GNU time binary
function M.time_path()
local path = find_gnu_time()
return path
@ -139,4 +137,29 @@ function M.update_buffer_content(bufnr, lines, highlights, namespace)
end
end
function M.check_required_runtime()
if is_windows() then
return false, 'Windows is not supported'
end
if vim.fn.has('nvim-0.10.0') ~= 1 then
return false, 'Neovim 0.10.0+ required'
end
local cap = M.time_capability()
if not cap.ok then
return false, 'GNU time not found: ' .. (cap.reason or '')
end
if vim.fn.executable('uv') ~= 1 then
return false, 'uv not found (https://docs.astral.sh/uv/)'
end
if not M.setup_python_env() then
return false, 'failed to set up Python virtual environment'
end
return true
end
return M