nix-community.nixvim/plugins/telescope/extensions/_helpers.nix

96 lines
2.3 KiB
Nix
Raw Normal View History

2024-03-24 17:42:40 +01:00
{
lib,
config,
helpers,
...
}:
2024-05-05 19:39:35 +02:00
with lib;
rec {
mkExtension =
{
name,
defaultPackage,
extensionName ? name,
settingsOptions ? { },
settingsExample ? null,
extraOptions ? { },
imports ? [ ],
optionsRenamedToSettings ? [ ],
extraConfig ? cfg: { },
}:
{
# TODO remove this once all deprecation warnings will have been removed.
imports =
let
basePluginPath = [
"plugins"
"telescope"
"extensions"
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
imports
++ (map (
option:
let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
2024-03-24 17:42:40 +01:00
optionPathSnakeCase = map helpers.toSnakeCase optionPath;
in
2024-05-05 19:39:35 +02:00
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);
2024-03-24 17:42:40 +01:00
2024-05-05 19:39:35 +02:00
options.plugins.telescope.extensions.${name} = {
2024-03-24 17:42:40 +01:00
enable = mkEnableOption "the `${name}` telescope extension";
package = helpers.mkPackageOption name defaultPackage;
settings = helpers.mkSettingsOption {
description = "settings for the `${name}` telescope extension.";
options = settingsOptions;
example = settingsExample;
};
2024-05-05 19:39:35 +02:00
} // extraOptions;
2024-03-24 17:42:40 +01:00
2024-05-05 19:39:35 +02:00
config =
let
cfg = config.plugins.telescope.extensions.${name};
in
mkIf cfg.enable (mkMerge [
2024-03-24 17:42:40 +01:00
{
2024-05-05 19:39:35 +02:00
extraPlugins = [ cfg.package ];
2024-03-24 17:42:40 +01:00
plugins.telescope = {
2024-05-05 19:39:35 +02:00
enabledExtensions = [ extensionName ];
2024-03-24 17:42:40 +01:00
settings.extensions.${extensionName} = cfg.settings;
};
}
(extraConfig cfg)
2024-05-05 19:39:35 +02:00
]);
};
2024-03-24 17:42:40 +01:00
2024-05-05 19:39:35 +02:00
mkModeMappingsOption =
mode: defaults:
2024-03-24 17:42:40 +01:00
mkOption {
type = with helpers.nixvimTypes; attrsOf strLuaFn;
2024-05-05 19:39:35 +02:00
default = { };
2024-03-24 17:42:40 +01:00
description = ''
Keymaps in ${mode} mode.
Default:
```nix
${defaults}
```
'';
apply = mapAttrs (_: helpers.mkRaw);
};
2024-05-05 19:39:35 +02:00
mkMappingsOption =
{ insertDefaults, normalDefaults }:
{
i = mkModeMappingsOption "insert" insertDefaults;
n = mkModeMappingsOption "normal" normalDefaults;
};
2024-03-24 17:42:40 +01:00
}