mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-10 09:14:31 +02:00
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:
parent
c674f10d18
commit
929bb0cd1c
11 changed files with 115 additions and 136 deletions
|
@ -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 =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue