|
27 | 27 | colorscheme ? name, |
28 | 28 | # luaConfig |
29 | 29 | configLocation ? if isColorscheme then "extraConfigLuaPre" else "extraConfigLua", |
30 | | - # For some plugins it may not make sense to have a configuration attribute, as they are |
31 | | - # configured through some other mean, like global variables |
32 | | - hasConfigAttrs ? true, |
| 30 | + # Some plugin are not supposed to generate lua configuration code. |
| 31 | + # For example, they might just be configured through some other mean, like global variables |
| 32 | + hasLuaConfig ? true, |
33 | 33 | # options |
34 | 34 | originalName ? name, |
35 | 35 | # Can be a string, a list of strings, or a module option: |
|
121 | 121 | example = settingsExample; |
122 | 122 | }; |
123 | 123 | } |
124 | | - // lib.optionalAttrs hasConfigAttrs { |
| 124 | + // lib.optionalAttrs hasLuaConfig { |
125 | 125 | luaConfig = lib.mkOption { |
126 | 126 | type = lib.types.pluginLuaConfig; |
127 | 127 | default = { }; |
|
132 | 132 |
|
133 | 133 | config = |
134 | 134 | assert lib.assertMsg ( |
135 | | - callSetup -> configLocation != null |
136 | | - ) "When a plugin has no config attrs and has a setup function it must have a config location"; |
| 135 | + callSetup -> hasLuaConfig |
| 136 | + ) "This plugin is supposed to call the `setup()` function but has `hasLuaConfig` set to false"; |
137 | 137 | lib.mkIf cfg.enable ( |
138 | 138 | lib.mkMerge ( |
139 | 139 | [ |
|
143 | 143 | (cfg.packageDecorator cfg.package) |
144 | 144 | ]; |
145 | 145 | } |
| 146 | + |
146 | 147 | (lib.optionalAttrs (isColorscheme && (colorscheme != null)) { |
147 | 148 | colorscheme = lib.mkDefault colorscheme; |
148 | 149 | }) |
| 150 | + |
| 151 | + # Apply any additional configuration added to `extraConfig` |
149 | 152 | (lib.optionalAttrs (args ? extraConfig) ( |
150 | 153 | lib.nixvim.modules.applyExtraConfig { |
151 | 154 | inherit extraConfig cfg opts; |
152 | 155 | } |
153 | 156 | )) |
154 | 157 | ] |
155 | | - ++ (lib.optionals (!hasConfigAttrs) [ |
156 | | - (lib.optionalAttrs callSetup (setLuaConfig setupCode)) |
157 | | - ]) |
158 | | - ++ (lib.optionals hasConfigAttrs [ |
| 158 | + # Lua configuration code generation |
| 159 | + ++ (lib.optionals hasLuaConfig [ |
| 160 | + |
| 161 | + # Add the plugin setup code `require('foo').setup(...)` to the lua configuration |
159 | 162 | (lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; }) |
160 | | - (lib.optionalAttrs (configLocation != null) (setLuaConfig cfg.luaConfig.content)) |
| 163 | + |
| 164 | + # Write the lua configuration `luaConfig.content` to the config file |
| 165 | + (setLuaConfig cfg.luaConfig.content) |
161 | 166 | ]) |
162 | 167 | ) |
163 | 168 | ); |
|
0 commit comments