@@ -7,7 +7,9 @@ _Lc_questions = {}
77--- @type lc.ui.menu
88_Lc_Menu = {} --- @diagnostic disable-line
99
10- --- @class lc.Settings
10+ local lazy_plugs = {}
11+
12+ --- @class lc.Config
1113local config = {
1214 default = template ,
1315 user = template ,
@@ -33,31 +35,34 @@ local config = {
3335---
3436--- @param cfg lc.UserConfig Configurations to be merged.
3537function config .apply (cfg )
36- cfg .storage = cfg .storage or {}
38+ config .user = vim .tbl_deep_extend (" force" , config .default , cfg or {})
39+ config .load_plugins ()
40+ end
41+
42+ function config .setup ()
43+ config .validate ()
3744
3845 -- deprecate `directory` config
39- if cfg .directory then
46+ if config . user .directory then
4047 local log = require (" leetcode.logger" )
41- log .warn (" Config : `directory` is deprecated. Use `storage.home` instead." )
42- cfg . storage .home = cfg .directory
48+ log .warn (" leetcode.nvim config : `directory` is deprecated. Use `storage.home` instead." )
49+ config . user . storage .home = config . user .directory
4350 end
4451
45- cfg .storage = vim .tbl_map (vim .fn .expand , cfg .storage )
46-
47- config .user = vim .tbl_deep_extend (" force" , config .default , cfg )
52+ config .user .storage = vim .tbl_map (vim .fn .expand , config .user .storage )
4853
4954 config .debug = config .user .debug or false --- @diagnostic disable-line
5055 config .lang = config .user .lang
5156
52- config .validate ()
53-
5457 config .storage .home = P :new (config .user .storage .home ) --- @diagnostic disable-line
5558 config .storage .home :mkdir ()
5659
5760 config .storage .cache = P :new (config .user .storage .cache ) --- @diagnostic disable-line
5861 config .storage .cache :mkdir ()
5962
60- config .load_plugins ()
63+ for _ , plug_load_fn in ipairs (lazy_plugs ) do
64+ plug_load_fn ()
65+ end
6166end
6267
6368function config .validate ()
8792function config .load_plugins ()
8893 local plugins = {}
8994
95+ if config .user .cn .enabled then table.insert (plugins , " cn" ) end
96+
97+ for _ , plugin in ipairs (plugins ) do
98+ local ok , plug = pcall (require , " leetcode-plugins." .. plugin )
99+ if ok then
100+ if not (plug .opts or {}).lazy then
101+ plug .load ()
102+ else
103+ table.insert (lazy_plugs , plug .load )
104+ end
105+ else
106+ local log = require (" leetcode.logger" )
107+ log .error (plug )
108+ end
109+ end
110+ end
111+
112+ function config .load_high_priority_plugins ()
113+ local plugins = {}
114+
90115 if config .user .cn .enabled then
91116 config .translator = config .user .cn .translator
92117 table.insert (plugins , " cn" )
0 commit comments