diff --git a/lib/option-warnings.nix b/lib/option-warnings.nix index 658e7a02..236cdb21 100644 --- a/lib/option-warnings.nix +++ b/lib/option-warnings.nix @@ -1,7 +1,7 @@ { lib, ... }: with lib; -{ +rec { # This should be used instead of mkRemovedOptionModule, when the option still works, # but is just deprecated and should be changed now and for the future mkDeprecatedOption = @@ -25,9 +25,56 @@ with lib; }; }; - # For removed options, we can just use nixpkgs mkRemovedOptionModule, which is already in lib - mkRemovedOption = mkRemovedOptionModule; + mkRenamedOption = + { option + , newOption + , visible ? false + , warn ? true + , overrideDescription ? null + }: + { options, ... }: + let + fromOpt = getAttrFromPath option options; + toOf = attrByPath newOption + (abort "Renaming error: option `${showOption newOption}` does not exist."); + toType = let opt = attrByPath newOption { } options; in + opt.type or (types.submodule { }); + message = "`${showOption option}` has been renamed to `${showOption newOption}`, but can still be used for compatibility"; + in + { + options = setAttrByPath option (mkOption + { + inherit visible; + description = + if overrideDescription == null + then message + else overrideDescription; + } // optionalAttrs (toType != null) { + type = toType; + }); + config = mkMerge [ + { + warnings = mkIf (warn) [ "Nixvim: ${message}" ]; + } + (mkAliasAndWrapDefinitions (setAttrByPath newOption) fromOpt) + ]; + }; - # For renamed options, we can also use the function from nixpkgs - mkRenamedOption = mkRenamedOptionModule; # use the function from nixpkgs + mkAliasOption = option: newOption: mkRenamedOption { + inherit option newOption; + visible = true; + warn = false; + overrideDescription = "Alias of ${showOption newOption}"; + }; + + # TODO: + # mkRemovedOption = + # { option + # , visible ? false + # }: + # { options, ... }: + # { + # options = { }; + # config = { }; + # }; } diff --git a/plugins/utils/nvim-tree.nix b/plugins/utils/nvim-tree.nix index 13188e40..94445999 100644 --- a/plugins/utils/nvim-tree.nix +++ b/plugins/utils/nvim-tree.nix @@ -8,8 +8,14 @@ let in { imports = [ - (optionWarnings.mkRenamedOption (basePluginPath ++ [ "updatedCwd" ]) (basePluginPath ++ [ "syncRootWithCwd" ])) - (optionWarnings.mkRenamedOption (basePluginPath ++ [ "updateFocusedFile" "updatedCwd" ]) (basePluginPath ++ [ "updateFocusedFile" "updateRoot" ])) + (optionWarnings.mkRenamedOption { + option = basePluginPath ++ [ "updateCwd" ]; + newOption = basePluginPath ++ [ "syncRootWithCwd" ]; + }) + (optionWarnings.mkRenamedOption { + option = basePluginPath ++ [ "updateFocusedFile" "updatedCwd" ]; + newOption = basePluginPath ++ [ "updateFocusedFile" "updateRoot" ]; + }) ]; options.plugins.nvim-tree = { @@ -231,7 +237,7 @@ in auto_close = cfg.autoClose; open_on_tab = cfg.openOnTab; hijack_cursor = cfg.hijackCursor; - sync_root_with_ced = cfg.syncRootWithCwd; + sync_root_with_cwd = cfg.syncRootWithCwd; respect_buf_cwd = cfg.respectBufCwd; update_to_buf_dir = { enable = cfg.updateToBufDir.enable;