plugins/telescope: refactor mkExtension

Allow importing `mkExtension` without needing to supply any
dependencies.

All dependencies can be accessed via module args anyway.
This commit is contained in:
Matt Sturgeon 2024-11-19 17:01:19 +00:00
parent c674f10d18
commit 929bb0cd1c
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
11 changed files with 115 additions and 136 deletions

View file

@ -1,85 +1,4 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib.nixvim) mkSettingsOption toSnakeCase;
inherit (lib) mkPackageOption;
in
rec {
mkExtension =
{
name,
package,
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 = lib.toList option;
optionPathSnakeCase = map toSnakeCase optionPath;
in
lib.mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);
options.plugins.telescope.extensions.${name} = {
enable = lib.mkEnableOption "the `${name}` telescope extension";
package = mkPackageOption pkgs name {
default = [
"vimPlugins"
package
];
};
settings = mkSettingsOption {
description = "settings for the `${name}` telescope extension.";
options = settingsOptions;
example = settingsExample;
};
} // extraOptions;
config =
let
cfg = config.plugins.telescope.extensions.${name};
in
lib.mkIf cfg.enable (
lib.mkMerge [
{
extraPlugins = [ cfg.package ];
plugins.telescope = {
enabledExtensions = [ extensionName ];
settings.extensions.${extensionName} = cfg.settings;
};
}
(extraConfig cfg)
]
);
};
lib: rec {
# FIXME: don't manually put Default in the description
# TODO: Comply with #603
mkModeMappingsOption =