|
59 | 59 | options = lib.setAttrByPath loc ( |
60 | 60 | { |
61 | 61 | enable = lib.mkEnableOption name; |
| 62 | + lazyLoad = lib.nixvim.mkLazyLoadOption name; |
62 | 63 | autoLoad = lib.nixvim.mkAutoLoadOption cfg name; |
63 | 64 | } |
64 | 65 | // settingsOption |
65 | 66 | // extraOptions |
66 | 67 | ); |
67 | 68 |
|
68 | 69 | config = lib.mkIf cfg.enable ( |
| 70 | + let |
| 71 | + globalsConfig = lib.nixvim.applyPrefixToAttrs globalPrefix (cfg.settings or { }); |
| 72 | + in |
69 | 73 | lib.mkMerge [ |
70 | | - { |
71 | | - inherit extraPackages extraPlugins; |
72 | | - globals = lib.nixvim.applyPrefixToAttrs globalPrefix (cfg.settings or { }); |
73 | | - } |
| 74 | + { inherit extraPackages extraPlugins; } |
| 75 | + |
| 76 | + (lib.mkIf cfg.lazyLoad.enable { |
| 77 | + assertions = [ |
| 78 | + { |
| 79 | + assertion = (isColorscheme && colorscheme != null) || cfg.lazyLoad.settings != { }; |
| 80 | + message = "You have enabled lazy loading for ${name} but have not provided any configuration."; |
| 81 | + } |
| 82 | + ]; |
| 83 | + |
| 84 | + plugins.lz-n = { |
| 85 | + plugins = [ |
| 86 | + ( |
| 87 | + { |
| 88 | + # The packpath name is always the derivation name |
| 89 | + __unkeyed-1 = lib.getName cfg.package; |
| 90 | + # Use provided before, otherwise fallback to normal function wrapped globals config |
| 91 | + before = |
| 92 | + let |
| 93 | + before = cfg.lazyLoad.settings.before or null; |
| 94 | + default = '' |
| 95 | + function() |
| 96 | + local globals = ${lib.nixvim.toLuaObject globalsConfig} |
| 97 | +
|
| 98 | + for k,v in pairs(globals) do |
| 99 | + vim.g[k] = v |
| 100 | + end |
| 101 | + end |
| 102 | + ''; |
| 103 | + in |
| 104 | + if (lib.isString before || lib.types.rawLua.check before) then before else default; |
| 105 | + colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme); |
| 106 | + } |
| 107 | + // lib.removeAttrs cfg.lazyLoad.settings [ |
| 108 | + "before" |
| 109 | + "colorscheme" |
| 110 | + ] |
| 111 | + ) |
| 112 | + ]; |
| 113 | + }; |
| 114 | + }) |
| 115 | + |
| 116 | + (lib.mkIf (!cfg.lazyLoad.enable) { |
| 117 | + globals = globalsConfig; |
| 118 | + }) |
| 119 | + |
74 | 120 | (lib.optionalAttrs (isColorscheme && colorscheme != null) { |
75 | 121 | colorscheme = lib.mkDefault colorscheme; |
76 | 122 | }) |
| 123 | + |
77 | 124 | (lib.optionalAttrs (args ? extraConfig) ( |
78 | 125 | lib.nixvim.plugins.utils.applyExtraConfig { |
79 | 126 | inherit extraConfig cfg opts; |
80 | 127 | } |
81 | 128 | )) |
| 129 | + |
82 | 130 | (lib.nixvim.plugins.utils.enableDependencies dependencies) |
83 | 131 | ] |
84 | 132 | ); |
|
0 commit comments