mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-01 04:44:31 +02:00
plugins/telescope: move to by-name
This commit is contained in:
parent
d07a9c78cc
commit
6debe9333f
19 changed files with 0 additions and 2 deletions
107
plugins/by-name/telescope/extensions/_helpers.nix
Normal file
107
plugins/by-name/telescope/extensions/_helpers.nix
Normal file
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
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)
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
# FIXME: don't manually put Default in the description
|
||||
# TODO: Comply with #603
|
||||
mkModeMappingsOption =
|
||||
mode: defaults:
|
||||
lib.mkOption {
|
||||
type = with lib.types; attrsOf strLuaFn;
|
||||
default = { };
|
||||
description = ''
|
||||
Keymaps in ${mode} mode.
|
||||
|
||||
Default:
|
||||
```nix
|
||||
${defaults}
|
||||
```
|
||||
'';
|
||||
apply = lib.mapAttrs (_: lib.nixvim.mkRaw);
|
||||
};
|
||||
|
||||
mkMappingsOption =
|
||||
{ insertDefaults, normalDefaults }:
|
||||
{
|
||||
i = mkModeMappingsOption "insert" insertDefaults;
|
||||
n = mkModeMappingsOption "normal" normalDefaults;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue