mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
mkNeovimPlugin: refactor lua code generation logic
This commit is contained in:
parent
f2a991ae8c
commit
cf7e026c8c
3 changed files with 18 additions and 14 deletions
|
@ -69,7 +69,7 @@ A template plugin can be found in (plugins/TEMPLATE.nix)[https://github.com/nix-
|
||||||
| **extraOptions** | Module options for the plugin, to be added _outside_ of the `settings` option. These should be Nixvim-specific options. | No | `{}` |
|
| **extraOptions** | Module options for the plugin, to be added _outside_ of the `settings` option. These should be Nixvim-specific options. | No | `{}` |
|
||||||
| **extraPackages** | Extra packages to include. | No | `[]` |
|
| **extraPackages** | Extra packages to include. | No | `[]` |
|
||||||
| **extraPlugins** | Extra plugins to include. | No | `[]` |
|
| **extraPlugins** | Extra plugins to include. | No | `[]` |
|
||||||
| **hasConfigAttrs** | Indicating whether the plugin has configuration attributes. | No | `true` |
|
| **hasLuaConfig** | Indicating whether the plugin generates lua configuration code (and thus should have a `luaConfig` option). | No | `true` |
|
||||||
| **hasSettings** | Indicating whether the plugin has settings. A `settings` option will be created if true. | No | `true` |
|
| **hasSettings** | Indicating whether the plugin has settings. A `settings` option will be created if true. | No | `true` |
|
||||||
| **imports** | Additional modules to import. | No | `[]` |
|
| **imports** | Additional modules to import. | No | `[]` |
|
||||||
| **isColorscheme** | Indicating whether the plugin is a colorscheme. | No | `false` |
|
| **isColorscheme** | Indicating whether the plugin is a colorscheme. | No | `false` |
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
colorscheme ? name,
|
colorscheme ? name,
|
||||||
# luaConfig
|
# luaConfig
|
||||||
configLocation ? if isColorscheme then "extraConfigLuaPre" else "extraConfigLua",
|
configLocation ? if isColorscheme then "extraConfigLuaPre" else "extraConfigLua",
|
||||||
# For some plugins it may not make sense to have a configuration attribute, as they are
|
# Some plugin are not supposed to generate lua configuration code.
|
||||||
# configured through some other mean, like global variables
|
# For example, they might just be configured through some other mean, like global variables
|
||||||
hasConfigAttrs ? true,
|
hasLuaConfig ? true,
|
||||||
# options
|
# options
|
||||||
originalName ? name,
|
originalName ? name,
|
||||||
# Can be a string, a list of strings, or a module option:
|
# Can be a string, a list of strings, or a module option:
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
example = settingsExample;
|
example = settingsExample;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs hasConfigAttrs {
|
// lib.optionalAttrs hasLuaConfig {
|
||||||
luaConfig = lib.mkOption {
|
luaConfig = lib.mkOption {
|
||||||
type = lib.types.pluginLuaConfig;
|
type = lib.types.pluginLuaConfig;
|
||||||
default = { };
|
default = { };
|
||||||
|
@ -132,8 +132,8 @@
|
||||||
|
|
||||||
config =
|
config =
|
||||||
assert lib.assertMsg (
|
assert lib.assertMsg (
|
||||||
callSetup -> configLocation != null
|
callSetup -> hasLuaConfig
|
||||||
) "When a plugin has no config attrs and has a setup function it must have a config location";
|
) "This plugin is supposed to call the `setup()` function but has `hasLuaConfig` set to false";
|
||||||
lib.mkIf cfg.enable (
|
lib.mkIf cfg.enable (
|
||||||
lib.mkMerge (
|
lib.mkMerge (
|
||||||
[
|
[
|
||||||
|
@ -143,21 +143,26 @@
|
||||||
(cfg.packageDecorator cfg.package)
|
(cfg.packageDecorator cfg.package)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
|
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
|
||||||
colorscheme = lib.mkDefault colorscheme;
|
colorscheme = lib.mkDefault colorscheme;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Apply any additional configuration added to `extraConfig`
|
||||||
(lib.optionalAttrs (args ? extraConfig) (
|
(lib.optionalAttrs (args ? extraConfig) (
|
||||||
lib.nixvim.modules.applyExtraConfig {
|
lib.nixvim.modules.applyExtraConfig {
|
||||||
inherit extraConfig cfg opts;
|
inherit extraConfig cfg opts;
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
]
|
]
|
||||||
++ (lib.optionals (!hasConfigAttrs) [
|
# Lua configuration code generation
|
||||||
(lib.optionalAttrs callSetup (setLuaConfig setupCode))
|
++ (lib.optionals hasLuaConfig [
|
||||||
])
|
|
||||||
++ (lib.optionals hasConfigAttrs [
|
# Add the plugin setup code `require('foo').setup(...)` to the lua configuration
|
||||||
(lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; })
|
(lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; })
|
||||||
(lib.optionalAttrs (configLocation != null) (setLuaConfig cfg.luaConfig.content))
|
|
||||||
|
# Write the lua configuration `luaConfig.content` to the config file
|
||||||
|
(setLuaConfig cfg.luaConfig.content)
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -48,8 +48,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
|
||||||
};
|
};
|
||||||
|
|
||||||
callSetup = false;
|
callSetup = false;
|
||||||
hasConfigAttrs = false;
|
hasLuaConfig = false;
|
||||||
configLocation = null;
|
|
||||||
extraConfig =
|
extraConfig =
|
||||||
cfg:
|
cfg:
|
||||||
mkMerge [
|
mkMerge [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue