From cddd61f061ccfdd6e838a6619d0af106dfad9d16 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 2 Oct 2025 23:20:51 -0400 Subject: [PATCH] config hard fail --- lua/cp/config.lua | 8 ++++++++ lua/cp/runner/execute.lua | 2 +- lua/cp/utils.lua | 29 ++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lua/cp/config.lua b/lua/cp/config.lua index 4788832..b5d56c5 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -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 diff --git a/lua/cp/runner/execute.lua b/lua/cp/runner/execute.lua index fe3667c..115f56a 100644 --- a/lua/cp/runner/execute.lua +++ b/lua/cp/runner/execute.lua @@ -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 diff --git a/lua/cp/utils.lua b/lua/cp/utils.lua index 60c23d8..033c924 100644 --- a/lua/cp/utils.lua +++ b/lua/cp/utils.lua @@ -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