|
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 | + lib.mkIf |
| 96 | + ( |
| 97 | + (lib.filterAttrs ( |
| 98 | + _: v: |
| 99 | + !builtins.elem v [ |
| 100 | + [ ] |
| 101 | + null |
| 102 | + { } |
| 103 | + ] |
| 104 | + ) globalsConfig) != { } |
| 105 | + ) |
| 106 | + '' |
| 107 | + function() |
| 108 | + local globals = ${lib.nixvim.toLuaObject globalsConfig} |
| 109 | +
|
| 110 | + for k,v in pairs(globals) do |
| 111 | + vim.g[k] = v |
| 112 | + end |
| 113 | + end |
| 114 | + ''; |
| 115 | + in |
| 116 | + if (lib.isString before || lib.types.rawLua.check before) then before else default; |
| 117 | + colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme); |
| 118 | + } |
| 119 | + // lib.removeAttrs cfg.lazyLoad.settings [ |
| 120 | + "before" |
| 121 | + "colorscheme" |
| 122 | + ] |
| 123 | + ) |
| 124 | + ]; |
| 125 | + }; |
| 126 | + }) |
| 127 | + |
| 128 | + (lib.mkIf (!cfg.lazyLoad.enable) { |
| 129 | + globals = globalsConfig; |
| 130 | + }) |
| 131 | + |
74 | 132 | (lib.optionalAttrs (isColorscheme && colorscheme != null) { |
75 | 133 | colorscheme = lib.mkDefault colorscheme; |
76 | 134 | }) |
| 135 | + |
77 | 136 | (lib.optionalAttrs (args ? extraConfig) ( |
78 | 137 | lib.nixvim.plugins.utils.applyExtraConfig { |
79 | 138 | inherit extraConfig cfg opts; |
80 | 139 | } |
81 | 140 | )) |
| 141 | + |
82 | 142 | (lib.nixvim.plugins.utils.enableDependencies dependencies) |
83 | 143 | ] |
84 | 144 | ); |
|
0 commit comments