From b8815f04a32c2fcff4c10f6a52aab0e030a71060 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Mon, 19 Feb 2024 10:29:19 +0100 Subject: [PATCH] helpers/vim-plugin/mkVimPlugin: add optionsRenamedToSettings option --- lib/helpers.nix | 2 +- lib/vim-plugin.nix | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/helpers.nix b/lib/helpers.nix index 5bf50b11..4103c115 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -14,7 +14,7 @@ in keymaps = import ./keymap-helpers.nix {inherit lib nixvimOptions nixvimTypes;}; autocmd = import ./autocmd-helpers.nix {inherit lib nixvimOptions nixvimTypes;}; neovim-plugin = import ./neovim-plugin.nix {inherit lib nixvimOptions nixvimUtils toLuaObject;}; - vim-plugin = import ./vim-plugin.nix {inherit lib nixvimOptions;}; + vim-plugin = import ./vim-plugin.nix {inherit lib nixvimOptions nixvimUtils;}; inherit nixvimTypes; inherit toLuaObject; } diff --git a/lib/vim-plugin.nix b/lib/vim-plugin.nix index 9331c78a..63b1422e 100644 --- a/lib/vim-plugin.nix +++ b/lib/vim-plugin.nix @@ -1,6 +1,7 @@ { lib, nixvimOptions, + nixvimUtils, }: with lib; { mkVimPlugin = config: { @@ -10,6 +11,7 @@ with lib; { imports ? [], # deprecations deprecateExtraConfig ? false, + optionsRenamedToSettings ? [], # options originalName ? name, defaultPackage ? null, @@ -88,12 +90,36 @@ with lib; { // pluginOptions // extraOptions; - imports = + imports = let + basePluginPath = [namespace name]; + settingsPath = basePluginPath ++ ["settings"]; + in imports - ++ optional (deprecateExtraConfig && createSettingsOption) ( - mkRenamedOptionModule - ["plugins" name "extraConfig"] - ["plugins" name "settings"] + ++ ( + 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 nixvimUtils.toSnakeCase optionPath; + in + mkRenamedOptionModule + (basePluginPath ++ optionPath) + (settingsPath ++ optionPathSnakeCase) + ) + optionsRenamedToSettings ); config =