2024-01-25 16:15:55 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
nixvimOptions,
|
2024-01-31 08:51:39 +01:00
|
|
|
toLuaObject,
|
2024-02-16 18:36:44 +01:00
|
|
|
nixvimUtils,
|
2024-01-25 16:15:55 +01:00
|
|
|
}:
|
2024-01-31 08:51:39 +01:00
|
|
|
with lib; rec {
|
2024-02-12 16:13:44 +01:00
|
|
|
mkSettingsOption = {
|
|
|
|
pluginName ? null,
|
|
|
|
options ? {},
|
|
|
|
description ?
|
|
|
|
if pluginName != null
|
|
|
|
then "Options provided to the `require('${pluginName}').setup` function."
|
|
|
|
else throw "mkSettingsOption: Please provide either a `pluginName` or `description`.",
|
|
|
|
example ? null,
|
|
|
|
}:
|
|
|
|
nixvimOptions.mkSettingsOption {
|
|
|
|
inherit options description example;
|
2024-01-25 16:17:36 +01:00
|
|
|
};
|
|
|
|
|
2024-02-12 16:13:44 +01:00
|
|
|
# TODO: DEPRECATED: use the `settings` option instead
|
2024-01-25 16:15:55 +01:00
|
|
|
extraOptionsOptions = {
|
|
|
|
extraOptions = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = with types; attrsOf anything;
|
|
|
|
description = ''
|
|
|
|
These attributes will be added to the table parameter for the setup function.
|
2024-02-11 12:51:34 +00:00
|
|
|
Typically, it can override NixVim's default settings.
|
2024-01-25 16:15:55 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-01-31 08:51:39 +01:00
|
|
|
|
|
|
|
mkNeovimPlugin = config: {
|
|
|
|
name,
|
2024-03-08 11:44:10 +01:00
|
|
|
colorscheme ? false,
|
2024-01-31 08:51:39 +01:00
|
|
|
maintainers,
|
2024-02-20 21:20:59 +01:00
|
|
|
url ? defaultPackage.meta.homepage,
|
2024-01-31 08:51:39 +01:00
|
|
|
imports ? [],
|
2024-02-16 18:36:44 +01:00
|
|
|
# deprecations
|
2024-02-19 00:24:10 +01:00
|
|
|
deprecateExtraOptions ? false,
|
2024-02-16 18:36:44 +01:00
|
|
|
optionsRenamedToSettings ? [],
|
2024-01-31 08:51:39 +01:00
|
|
|
# options
|
|
|
|
originalName ? name,
|
|
|
|
defaultPackage,
|
|
|
|
settingsOptions ? {},
|
|
|
|
settingsExample ? null,
|
|
|
|
extraOptions ? {},
|
|
|
|
# config
|
|
|
|
luaName ? name,
|
|
|
|
extraConfig ? cfg: {},
|
|
|
|
extraPlugins ? [],
|
|
|
|
extraPackages ? [],
|
2024-02-16 18:36:33 +01:00
|
|
|
callSetup ? true,
|
2024-03-08 11:44:10 +01:00
|
|
|
}: let
|
|
|
|
namespace =
|
|
|
|
if colorscheme
|
|
|
|
then "colorschemes"
|
|
|
|
else "plugins";
|
|
|
|
in {
|
2024-02-20 21:20:59 +01:00
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
|
|
|
inherit name url;
|
|
|
|
kind = namespace;
|
|
|
|
};
|
|
|
|
};
|
2024-01-31 08:51:39 +01:00
|
|
|
|
2024-02-16 18:36:44 +01:00
|
|
|
imports = let
|
|
|
|
basePluginPath = [namespace name];
|
2024-02-19 10:59:18 +01:00
|
|
|
settingsPath = basePluginPath ++ ["settings"];
|
2024-02-16 18:36:44 +01:00
|
|
|
in
|
|
|
|
imports
|
|
|
|
++ (
|
|
|
|
optional
|
2024-02-19 00:24:10 +01:00
|
|
|
deprecateExtraOptions
|
2024-02-16 18:36:44 +01:00
|
|
|
(
|
|
|
|
mkRenamedOptionModule
|
2024-02-19 00:24:10 +01:00
|
|
|
(basePluginPath ++ ["extraOptions"])
|
2024-02-19 10:59:18 +01:00
|
|
|
settingsPath
|
2024-02-16 18:36:44 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
++ (
|
|
|
|
map
|
|
|
|
(
|
2024-02-19 10:59:18 +01:00
|
|
|
option: let
|
|
|
|
optionPath =
|
|
|
|
if isString option
|
|
|
|
then [option]
|
|
|
|
else option; # option is already a path (i.e. a list)
|
|
|
|
|
|
|
|
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
|
|
|
|
in
|
2024-02-16 18:36:44 +01:00
|
|
|
mkRenamedOptionModule
|
2024-02-19 10:59:18 +01:00
|
|
|
(basePluginPath ++ optionPath)
|
|
|
|
(settingsPath ++ optionPathSnakeCase)
|
2024-02-16 18:36:44 +01:00
|
|
|
)
|
|
|
|
optionsRenamedToSettings
|
|
|
|
);
|
2024-01-31 08:51:39 +01:00
|
|
|
|
|
|
|
options.${namespace}.${name} =
|
|
|
|
{
|
|
|
|
enable = mkEnableOption originalName;
|
|
|
|
|
|
|
|
package = nixvimOptions.mkPackageOption originalName defaultPackage;
|
|
|
|
|
|
|
|
settings = mkSettingsOption {
|
|
|
|
pluginName = name;
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// extraOptions;
|
|
|
|
|
|
|
|
config = let
|
|
|
|
cfg = config.${namespace}.${name};
|
2024-03-08 11:44:10 +01:00
|
|
|
extraConfigNamespace =
|
|
|
|
if colorscheme
|
|
|
|
then "extraConfigLuaPre"
|
|
|
|
else "extraConfigLua";
|
2024-01-31 08:51:39 +01:00
|
|
|
in
|
|
|
|
mkIf cfg.enable (
|
|
|
|
mkMerge [
|
|
|
|
{
|
|
|
|
extraPlugins = [cfg.package] ++ extraPlugins;
|
|
|
|
inherit extraPackages;
|
|
|
|
|
2024-03-08 11:44:10 +01:00
|
|
|
${extraConfigNamespace} = optionalString callSetup ''
|
2024-01-31 08:51:39 +01:00
|
|
|
require('${luaName}').setup(${toLuaObject cfg.settings})
|
|
|
|
'';
|
|
|
|
}
|
2024-03-08 11:44:10 +01:00
|
|
|
(optionalAttrs colorscheme {
|
|
|
|
# We use `mkDefault` here to let individual plugins override this option.
|
|
|
|
# For instance, setting it to `null` a specific way of setting the coloscheme.
|
|
|
|
colorscheme = lib.mkDefault name;
|
|
|
|
})
|
2024-01-31 08:51:39 +01:00
|
|
|
(extraConfig cfg)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
};
|
2024-01-25 16:15:55 +01:00
|
|
|
}
|