From d23b4e59d15018472a3eb6c397f7e74cf2a6eaa9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Feb 2026 16:29:46 -0500 Subject: [PATCH] fix(setup): set language state before setup_code hook on first open Problem: when opening a contest for the first time (metadata not cached), the setup_code hook fired before state.set_language() was called, causing state.get_language() to return nil inside the hook. Solution: call state.set_language(lang) before the hook in the provisional-buffer branch of setup_contest(). The value is already computed at that point and is identical to what setup_problem() sets later, so the early write is idempotent. --- lua/cp/setup.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index fce1a0c..e3bb38d 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -160,6 +160,8 @@ function M.setup_contest(platform, contest_id, problem_id, language) vim.bo[bufnr].buftype = '' vim.bo[bufnr].swapfile = false + state.set_language(lang) + if cfg.hooks and cfg.hooks.setup_code and not vim.b[bufnr].cp_setup_done then local ok = pcall(cfg.hooks.setup_code, state) if ok then