From c1c9674503f5c4cda6a69589c644e5aa70604525 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 14 Sep 2025 00:05:09 -0500 Subject: [PATCH] feat: lazy load --- lua/cp/health.lua | 6 +----- lua/cp/init.lua | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lua/cp/health.lua b/lua/cp/health.lua index 7c66c21..b5981ca 100644 --- a/lua/cp/health.lua +++ b/lua/cp/health.lua @@ -61,8 +61,7 @@ end local function check_config() local cp = require("cp") - if cp.is_initialized() then - vim.health.ok("Plugin initialized") + vim.health.ok("Plugin ready") if vim.g.cp and vim.g.cp.platform then local info = vim.g.cp.platform @@ -76,9 +75,6 @@ local function check_config() else vim.health.info("No contest context set") end - else - vim.health.warn("Plugin not initialized - configuration may be incomplete") - end end function M.check() diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 7950714..e457afd 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -1,18 +1,25 @@ -local config_module = require("cp.config") -local snippets = require("cp.snippets") -local execute = require("cp.execute") -local scrape = require("cp.scrape") -local window = require("cp.window") -local logger = require("cp.log") -local problem = require("cp.problem") -local cache = require("cp.cache") - local M = {} local config = {} -if not vim.fn.has("nvim-0.10.0") then - logger.log("cp.nvim requires nvim-0.10.0+", vim.log.levels.ERROR) - return M +local config_module, snippets, execute, scrape, window, logger, problem, cache + +local function lazy_require() + if not config_module then + if not vim.fn.has("nvim-0.10.0") then + vim.notify("[cp.nvim]: requires nvim-0.10.0+", vim.log.levels.ERROR) + return false + end + + config_module = require("cp.config") + snippets = require("cp.snippets") + execute = require("cp.execute") + scrape = require("cp.scrape") + window = require("cp.window") + logger = require("cp.log") + problem = require("cp.problem") + cache = require("cp.cache") + end + return true end local platforms = { "atcoder", "codeforces", "cses" } @@ -268,6 +275,10 @@ local function ensure_initialized() return end + if not lazy_require() then + return + end + vim.g.cp = vim.g.cp or {} config = config_module.setup(vim.g.cp.config) logger.set_config(config)