Fixed mkRenamedOption

This commit is contained in:
Alexander Nortung 2023-01-22 21:10:36 +01:00
parent 57eb1c09a9
commit 65fdfdc0eb
2 changed files with 61 additions and 8 deletions

View file

@ -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 = { };
# };
}

View file

@ -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;