diff --git a/plugins/by-name/telescope/extensions/_helpers.nix b/plugins/by-name/telescope/extensions/_helpers.nix index 75f66dc9ed..e511ffa5ba 100644 --- a/plugins/by-name/telescope/extensions/_helpers.nix +++ b/plugins/by-name/telescope/extensions/_helpers.nix @@ -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 = diff --git a/plugins/by-name/telescope/extensions/_mk-extension.nix b/plugins/by-name/telescope/extensions/_mk-extension.nix new file mode 100644 index 0000000000..834f8454c3 --- /dev/null +++ b/plugins/by-name/telescope/extensions/_mk-extension.nix @@ -0,0 +1,85 @@ +{ + name, + package, + extensionName ? name, + settingsOptions ? { }, + settingsExample ? null, + extraOptions ? { }, + imports ? [ ], + optionsRenamedToSettings ? [ ], + extraConfig ? cfg: { }, +}: +let + getPluginAttr = attrs: attrs.plugins.telescope.extensions.${name}; + + renameModule = + { lib, ... }: + { + # TODO remove this once all deprecation warnings will have been removed. + imports = + let + basePluginPath = [ + "plugins" + "telescope" + "extensions" + name + ]; + settingsPath = basePluginPath ++ [ "settings" ]; + in + builtins.map ( + option: + let + optionPath = lib.toList option; + optionPathSnakeCase = map lib.nixvim.toSnakeCase optionPath; + in + lib.mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase) + ) optionsRenamedToSettings; + }; + + module = + { + lib, + config, + pkgs, + ... + }: + let + cfg = getPluginAttr config; + in + { + options.plugins.telescope.extensions.${name} = { + enable = lib.mkEnableOption "the `${name}` telescope extension"; + + package = lib.mkPackageOption pkgs name { + default = [ + "vimPlugins" + package + ]; + }; + + settings = lib.nixvim.mkSettingsOption { + description = "settings for the `${name}` telescope extension."; + options = settingsOptions; + example = settingsExample; + }; + } // extraOptions; + + config = lib.mkIf cfg.enable { + extraPlugins = [ cfg.package ]; + + plugins.telescope = { + enabledExtensions = [ extensionName ]; + settings.extensions.${extensionName} = cfg.settings; + }; + }; + }; + + extraConfigModule = { config, ... }: extraConfig (getPluginAttr config); +in +{ + imports = imports ++ [ + module + extraConfigModule + renameModule + ]; +} diff --git a/plugins/by-name/telescope/extensions/file-browser.nix b/plugins/by-name/telescope/extensions/file-browser.nix index e6973e8640..e060181e63 100644 --- a/plugins/by-name/telescope/extensions/file-browser.nix +++ b/plugins/by-name/telescope/extensions/file-browser.nix @@ -1,15 +1,11 @@ -{ - lib, - config, - pkgs, - ... -}: +{ lib, ... }: with lib; let - telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; }; + inherit (import ./_helpers.nix lib) mkMappingsOption; + mkExtension = import ./_mk-extension.nix; inherit (lib.nixvim) defaultNullOpts mkNullOrStr; in -telescopeHelpers.mkExtension { +mkExtension { name = "file-browser"; extensionName = "file_browser"; package = "telescope-file-browser-nvim"; @@ -183,7 +179,7 @@ telescopeHelpers.mkExtension { Show the current relative path from cwd as the prompt prefix. ''; - mappings = telescopeHelpers.mkMappingsOption { + mappings = mkMappingsOption { insertDefaults = '' { "" = "require('telescope._extensions.file_browser.actions').create"; diff --git a/plugins/by-name/telescope/extensions/frecency.nix b/plugins/by-name/telescope/extensions/frecency.nix index 41b8471f20..497ca48350 100644 --- a/plugins/by-name/telescope/extensions/frecency.nix +++ b/plugins/by-name/telescope/extensions/frecency.nix @@ -1,14 +1,10 @@ -{ - lib, - config, - pkgs, - ... -}: +{ lib, ... }: with lib; let inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrStr; + mkExtension = import ./_mk-extension.nix; in -(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension { +mkExtension { name = "frecency"; package = "telescope-frecency-nvim"; diff --git a/plugins/by-name/telescope/extensions/fzf-native.nix b/plugins/by-name/telescope/extensions/fzf-native.nix index 458650b944..f012e1e6cc 100644 --- a/plugins/by-name/telescope/extensions/fzf-native.nix +++ b/plugins/by-name/telescope/extensions/fzf-native.nix @@ -1,13 +1,9 @@ -{ - lib, - config, - pkgs, - ... -}: +{ lib, ... }: let inherit (lib.nixvim) defaultNullOpts; + mkExtension = import ./_mk-extension.nix; in -(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension { +mkExtension { name = "fzf-native"; extensionName = "fzf"; package = "telescope-fzf-native-nvim"; diff --git a/plugins/by-name/telescope/extensions/fzy-native.nix b/plugins/by-name/telescope/extensions/fzy-native.nix index a5fe01cdf3..c83c651fef 100644 --- a/plugins/by-name/telescope/extensions/fzy-native.nix +++ b/plugins/by-name/telescope/extensions/fzy-native.nix @@ -1,13 +1,9 @@ -{ - lib, - config, - pkgs, - ... -}: +{ lib, ... }: let inherit (lib.nixvim) defaultNullOpts; + mkExtension = import ./_mk-extension.nix; in -(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension { +mkExtension { name = "fzy-native"; extensionName = "fzy_native"; package = "telescope-fzy-native-nvim"; diff --git a/plugins/by-name/telescope/extensions/live-greps-args.nix b/plugins/by-name/telescope/extensions/live-greps-args.nix index 03ccf5141f..4960162e01 100644 --- a/plugins/by-name/telescope/extensions/live-greps-args.nix +++ b/plugins/by-name/telescope/extensions/live-greps-args.nix @@ -1,15 +1,14 @@ { lib, - config, pkgs, ... }: let inherit (lib.nixvim) defaultNullOpts; inherit (lib) types; - telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; }; + mkExtension = import ./_mk-extension.nix; in -telescopeHelpers.mkExtension { +mkExtension { name = "live-grep-args"; extensionName = "live_grep_args"; package = "telescope-live-grep-args-nvim"; diff --git a/plugins/by-name/telescope/extensions/manix.nix b/plugins/by-name/telescope/extensions/manix.nix index dfe55f7a2a..64a1d87c6b 100644 --- a/plugins/by-name/telescope/extensions/manix.nix +++ b/plugins/by-name/telescope/extensions/manix.nix @@ -1,15 +1,14 @@ { lib, - config, pkgs, ... }: let inherit (lib.nixvim) defaultNullOpts; - telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; }; + mkExtension = import ./_mk-extension.nix; in -telescopeHelpers.mkExtension { +mkExtension { name = "manix"; package = "telescope-manix"; diff --git a/plugins/by-name/telescope/extensions/media-files.nix b/plugins/by-name/telescope/extensions/media-files.nix index ccba94185f..e6b376de88 100644 --- a/plugins/by-name/telescope/extensions/media-files.nix +++ b/plugins/by-name/telescope/extensions/media-files.nix @@ -1,14 +1,14 @@ { lib, - config, pkgs, ... }: with lib; let inherit (lib.nixvim) defaultNullOpts; + mkExtension = import ./_mk-extension.nix; in -(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension { +mkExtension { name = "media-files"; extensionName = "media_files"; package = "telescope-media-files-nvim"; diff --git a/plugins/by-name/telescope/extensions/ui-select.nix b/plugins/by-name/telescope/extensions/ui-select.nix index e1930e4268..0b37225149 100644 --- a/plugins/by-name/telescope/extensions/ui-select.nix +++ b/plugins/by-name/telescope/extensions/ui-select.nix @@ -1,10 +1,7 @@ -{ - lib, - config, - pkgs, - ... -}: -(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension { +let + mkExtension = import ./_mk-extension.nix; +in +mkExtension { name = "ui-select"; package = "telescope-ui-select-nvim"; diff --git a/plugins/by-name/telescope/extensions/undo.nix b/plugins/by-name/telescope/extensions/undo.nix index 2f059f9eec..7e2cd717ff 100644 --- a/plugins/by-name/telescope/extensions/undo.nix +++ b/plugins/by-name/telescope/extensions/undo.nix @@ -1,15 +1,11 @@ -{ - lib, - config, - pkgs, - ... -}: +{ lib, ... }: with lib; let inherit (lib.nixvim) defaultNullOpts mkNullOrOption; - telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; }; + inherit (import ./_helpers.nix lib) mkMappingsOption; + mkExtension = import ./_mk-extension.nix; in -telescopeHelpers.mkExtension { +mkExtension { name = "undo"; package = "telescope-undo-nvim"; @@ -84,7 +80,7 @@ telescopeHelpers.mkExtension { Can be set to a [Lua date format string](https://www.lua.org/pil/22.1.html). ''; - mappings = telescopeHelpers.mkMappingsOption { + mappings = mkMappingsOption { insertDefaults = '' { "" = "require('telescope-undo.actions').yank_additions";