From 276241447c3699f56704d286d6e343adcf019867 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 3 Feb 2026 21:46:47 -0500 Subject: [PATCH 1/4] fix: add deprecation warning for setup() --- lua/cp/init.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/cp/init.lua b/lua/cp/init.lua index fac3044..0bb5582 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -34,4 +34,13 @@ function M.is_initialized() return initialized end +---@deprecated Use `vim.g.cp_config` instead +function M.setup(user_config) + vim.deprecate('require("cp").setup()', 'vim.g.cp_config', 'v0.1.0', 'cp.nvim', false) + + if user_config then + vim.g.cp_config = vim.tbl_deep_extend('force', vim.g.cp_config or {}, user_config) + end +end + return M From a54a06f9396213725a06aab58e023ec6d8e20f37 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Feb 2026 15:12:47 -0500 Subject: [PATCH 2/4] refactor: rename `vim.g.cp_config` to `vim.g.cp` --- doc/cp.nvim.txt | 8 ++++---- lua/cp/init.lua | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/cp.nvim.txt b/doc/cp.nvim.txt index d6d1d73..17fd18c 100644 --- a/doc/cp.nvim.txt +++ b/doc/cp.nvim.txt @@ -205,9 +205,9 @@ Debug Builds ~ ============================================================================== CONFIGURATION *cp-config* -Configuration is done via `vim.g.cp_config`. Set this before using the plugin: +Configuration is done via `vim.g.cp`. Set this before using the plugin: >lua - vim.g.cp_config = { + vim.g.cp = { languages = { cpp = { extension = 'cc', @@ -274,7 +274,7 @@ the default; per-platform overrides can tweak 'extension' or 'commands'. For example, to run CodeForces contests with Python by default: >lua - vim.g.cp_config = { + vim.g.cp = { platforms = { codeforces = { default_language = 'python', @@ -285,7 +285,7 @@ For example, to run CodeForces contests with Python by default: Any language is supported provided the proper configuration. For example, to run CSES problems with Rust using the single schema: >lua - vim.g.cp_config = { + vim.g.cp = { languages = { rust = { extension = 'rs', diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 0bb5582..1837901 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -17,7 +17,11 @@ local function ensure_initialized() if initialized then return end - local user_config = vim.g.cp_config or {} + if vim.g.cp_config then + vim.deprecate('vim.g.cp_config', 'vim.g.cp', 'v0.7.6', 'cp.nvim', false) + vim.g.cp = vim.g.cp or vim.g.cp_config + end + local user_config = vim.g.cp or {} local config = config_module.setup(user_config) config_module.set_current_config(config) initialized = true @@ -34,12 +38,12 @@ function M.is_initialized() return initialized end ----@deprecated Use `vim.g.cp_config` instead +---@deprecated Use `vim.g.cp` instead function M.setup(user_config) - vim.deprecate('require("cp").setup()', 'vim.g.cp_config', 'v0.1.0', 'cp.nvim', false) + vim.deprecate('require("cp").setup()', 'vim.g.cp', 'v0.1.0', 'cp.nvim', false) if user_config then - vim.g.cp_config = vim.tbl_deep_extend('force', vim.g.cp_config or {}, user_config) + vim.g.cp = vim.tbl_deep_extend('force', vim.g.cp or {}, user_config) end end From d23b4e59d15018472a3eb6c397f7e74cf2a6eaa9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Feb 2026 16:29:46 -0500 Subject: [PATCH 3/4] 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 From de2bc0753228be518d0cf0a6d5614c281d5b3144 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Feb 2026 16:40:39 -0500 Subject: [PATCH 4/4] refactor: remove vim.g.cp_config compatibility shim Problem: the deprecated vim.g.cp_config fallback was kept for backwards compatibility after the rename to vim.g.cp in v0.7.6. Solution: drop the shim entirely and update the setup() deprecation target to v0.7.7. --- lua/cp/init.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 1837901..3cb36c1 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -17,10 +17,6 @@ local function ensure_initialized() if initialized then return end - if vim.g.cp_config then - vim.deprecate('vim.g.cp_config', 'vim.g.cp', 'v0.7.6', 'cp.nvim', false) - vim.g.cp = vim.g.cp or vim.g.cp_config - end local user_config = vim.g.cp or {} local config = config_module.setup(user_config) config_module.set_current_config(config) @@ -40,7 +36,7 @@ end ---@deprecated Use `vim.g.cp` instead function M.setup(user_config) - vim.deprecate('require("cp").setup()', 'vim.g.cp', 'v0.1.0', 'cp.nvim', false) + vim.deprecate('require("cp").setup()', 'vim.g.cp', 'v0.7.7', 'cp.nvim', false) if user_config then vim.g.cp = vim.tbl_deep_extend('force', vim.g.cp or {}, user_config)