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-05-05 19:39:35 +02:00
|
|
|
with lib;
|
|
|
|
rec {
|
|
|
|
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 {
|
2024-05-05 19:39:35 +02:00
|
|
|
default = { };
|
2024-01-25 16:15:55 +01:00
|
|
|
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
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkNeovimPlugin =
|
|
|
|
config:
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
maintainers,
|
|
|
|
url ? defaultPackage.meta.homepage,
|
|
|
|
imports ? [ ],
|
|
|
|
description ? null,
|
|
|
|
# deprecations
|
|
|
|
deprecateExtraOptions ? false,
|
|
|
|
optionsRenamedToSettings ? [ ],
|
|
|
|
# colorscheme
|
|
|
|
isColorscheme ? false,
|
|
|
|
colorscheme ? name,
|
|
|
|
# options
|
|
|
|
originalName ? name,
|
|
|
|
defaultPackage,
|
|
|
|
settingsOptions ? { },
|
|
|
|
settingsExample ? null,
|
|
|
|
extraOptions ? { },
|
|
|
|
# config
|
|
|
|
luaName ? name,
|
|
|
|
extraConfig ? cfg: { },
|
|
|
|
extraPlugins ? [ ],
|
|
|
|
extraPackages ? [ ],
|
|
|
|
callSetup ? true,
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
namespace = if isColorscheme then "colorschemes" else "plugins";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
2024-06-07 21:30:00 +01:00
|
|
|
inherit description url;
|
|
|
|
path = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2024-02-20 21:20:59 +01:00
|
|
|
};
|
2024-01-31 08:51:39 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
imports =
|
|
|
|
let
|
|
|
|
basePluginPath = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
settingsPath = basePluginPath ++ [ "settings" ];
|
|
|
|
in
|
|
|
|
imports
|
|
|
|
++ (optional deprecateExtraOptions (
|
|
|
|
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
|
|
|
|
))
|
|
|
|
++ (map (
|
|
|
|
option:
|
|
|
|
let
|
|
|
|
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
|
2024-02-19 10:59:18 +01:00
|
|
|
|
|
|
|
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
|
|
|
|
in
|
2024-05-05 19:39:35 +02:00
|
|
|
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
|
|
|
|
) optionsRenamedToSettings);
|
2024-01-31 08:51:39 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
options.${namespace}.${name} = {
|
2024-01-31 08:51:39 +01:00
|
|
|
enable = mkEnableOption originalName;
|
|
|
|
|
2024-05-17 14:09:20 +02:00
|
|
|
package = nixvimOptions.mkPluginPackageOption originalName defaultPackage;
|
2024-01-31 08:51:39 +01:00
|
|
|
|
|
|
|
settings = mkSettingsOption {
|
|
|
|
pluginName = name;
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
} // extraOptions;
|
2024-01-31 08:51:39 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.${namespace}.${name};
|
|
|
|
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
|
|
|
|
in
|
|
|
|
mkIf cfg.enable (mkMerge [
|
2024-01-31 08:51:39 +01:00
|
|
|
{
|
2024-05-05 19:39:35 +02:00
|
|
|
extraPlugins = [ cfg.package ] ++ extraPlugins;
|
2024-01-31 08:51:39 +01:00
|
|
|
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-05-28 21:22:35 +02:00
|
|
|
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
|
2024-01-31 08:51:39 +01:00
|
|
|
(extraConfig cfg)
|
2024-05-05 19:39:35 +02:00
|
|
|
]);
|
|
|
|
};
|
2024-01-25 16:15:55 +01:00
|
|
|
}
|