From db4c4e5b1707f334a3e11530cb253d2f41051a3f Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 13 Aug 2024 09:23:17 -0500 Subject: [PATCH] lib/deprecation: expose `mkSettingsRenamedOptionModules` publicly Extracted the `optionsRenamedToSettings` implementation from`mkVimPlugin` and `mkNeovimPlugin` into a new public helper. --- lib/deprecation.nix | 12 ++++++++++++ lib/helpers.nix | 7 ++++++- lib/neovim-plugin.nix | 10 +--------- lib/vim-plugin.nix | 10 +--------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/deprecation.nix b/lib/deprecation.nix index 51bc63b9..3ab0c975 100644 --- a/lib/deprecation.nix +++ b/lib/deprecation.nix @@ -46,6 +46,18 @@ rec { ''; }; + mkSettingsRenamedOptionModules = + oldPrefix: newPrefix: + map ( + option': + let + option = toList option'; + oldPath = oldPrefix ++ option; + newPath = newPrefix ++ map nixvim.toSnakeCase option; + in + mkRenamedOptionModule oldPath newPath + ); + # A clone of types.coercedTo, but it prints a warning when oldType is used. transitionType = oldType: coerceFn: newType: diff --git a/lib/helpers.nix b/lib/helpers.nix index 9c920d63..86ac4346 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -38,7 +38,12 @@ let byteCompileLuaDrv ; - inherit (helpers.deprecation) getOptionRecursive mkDeprecatedSubOptionModule transitionType; + inherit (helpers.deprecation) + getOptionRecursive + mkDeprecatedSubOptionModule + mkSettingsRenamedOptionModules + transitionType + ; inherit (helpers.options) defaultNullOpts diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 4095bbf4..7edc362d 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -71,15 +71,7 @@ with lib; ++ (optional deprecateExtraOptions ( mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath )) - ++ (map ( - option: - let - optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list) - - optionPathSnakeCase = map helpers.toSnakeCase optionPath; - in - mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase) - ) optionsRenamedToSettings); + ++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings); options.${namespace}.${name} = { diff --git a/lib/vim-plugin.nix b/lib/vim-plugin.nix index 09b64de5..f975096a 100644 --- a/lib/vim-plugin.nix +++ b/lib/vim-plugin.nix @@ -86,15 +86,7 @@ with lib; ++ (optional (deprecateExtraConfig && createSettingsOption) ( mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath )) - ++ (map ( - option: - let - optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list) - - optionPathSnakeCase = map helpers.toSnakeCase optionPath; - in - mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase) - ) optionsRenamedToSettings); + ++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings); config = mkIf cfg.enable (mkMerge [ {