feat: local state over vim.g

This commit is contained in:
Barrett Ruth 2025-09-15 07:05:31 -05:00
parent e81ea9ef4d
commit 67d2a8054c
4 changed files with 224 additions and 42 deletions

View file

@ -4,7 +4,7 @@ end
vim.g.loaded_cp = 1
local platforms = { "atcoder", "codeforces", "cses" }
local actions = { "run", "debug", "diff", "next", "prev" }
local actions = { "run", "debug", "test", "next", "prev" }
vim.api.nvim_create_user_command("CP", function(opts)
local cp = require("cp")
@ -22,10 +22,12 @@ end, {
local candidates = {}
vim.list_extend(candidates, platforms)
vim.list_extend(candidates, actions)
if vim.g.cp and vim.g.cp.platform and vim.g.cp.contest_id then
local cp = require("cp")
local context = cp.get_current_context()
if context.platform and context.contest_id then
local cache = require("cp.cache")
cache.load()
local contest_data = cache.get_contest_data(vim.g.cp.platform, vim.g.cp.contest_id)
local contest_data = cache.get_contest_data(context.platform, context.contest_id)
if contest_data and contest_data.problems then
for _, problem in ipairs(contest_data.problems) do
table.insert(candidates, problem.id)