mirror of
https://github.com/nix-community/nixvim.git
synced 2025-08-07 11:25:06 +02:00
Fixed mkRenamedOption
This commit is contained in:
parent
57eb1c09a9
commit
65fdfdc0eb
2 changed files with 61 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
{
|
rec {
|
||||||
# This should be used instead of mkRemovedOptionModule, when the option still works,
|
# 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
|
# but is just deprecated and should be changed now and for the future
|
||||||
mkDeprecatedOption =
|
mkDeprecatedOption =
|
||||||
|
@ -25,9 +25,56 @@ with lib;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# For removed options, we can just use nixpkgs mkRemovedOptionModule, which is already in lib
|
mkRenamedOption =
|
||||||
mkRemovedOption = mkRemovedOptionModule;
|
{ 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
|
mkAliasOption = option: newOption: mkRenamedOption {
|
||||||
mkRenamedOption = mkRenamedOptionModule; # use the function from nixpkgs
|
inherit option newOption;
|
||||||
|
visible = true;
|
||||||
|
warn = false;
|
||||||
|
overrideDescription = "Alias of ${showOption newOption}";
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
# mkRemovedOption =
|
||||||
|
# { option
|
||||||
|
# , visible ? false
|
||||||
|
# }:
|
||||||
|
# { options, ... }:
|
||||||
|
# {
|
||||||
|
# options = { };
|
||||||
|
# config = { };
|
||||||
|
# };
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,14 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(optionWarnings.mkRenamedOption (basePluginPath ++ [ "updatedCwd" ]) (basePluginPath ++ [ "syncRootWithCwd" ]))
|
(optionWarnings.mkRenamedOption {
|
||||||
(optionWarnings.mkRenamedOption (basePluginPath ++ [ "updateFocusedFile" "updatedCwd" ]) (basePluginPath ++ [ "updateFocusedFile" "updateRoot" ]))
|
option = basePluginPath ++ [ "updateCwd" ];
|
||||||
|
newOption = basePluginPath ++ [ "syncRootWithCwd" ];
|
||||||
|
})
|
||||||
|
(optionWarnings.mkRenamedOption {
|
||||||
|
option = basePluginPath ++ [ "updateFocusedFile" "updatedCwd" ];
|
||||||
|
newOption = basePluginPath ++ [ "updateFocusedFile" "updateRoot" ];
|
||||||
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
options.plugins.nvim-tree = {
|
options.plugins.nvim-tree = {
|
||||||
|
@ -231,7 +237,7 @@ in
|
||||||
auto_close = cfg.autoClose;
|
auto_close = cfg.autoClose;
|
||||||
open_on_tab = cfg.openOnTab;
|
open_on_tab = cfg.openOnTab;
|
||||||
hijack_cursor = cfg.hijackCursor;
|
hijack_cursor = cfg.hijackCursor;
|
||||||
sync_root_with_ced = cfg.syncRootWithCwd;
|
sync_root_with_cwd = cfg.syncRootWithCwd;
|
||||||
respect_buf_cwd = cfg.respectBufCwd;
|
respect_buf_cwd = cfg.respectBufCwd;
|
||||||
update_to_buf_dir = {
|
update_to_buf_dir = {
|
||||||
enable = cfg.updateToBufDir.enable;
|
enable = cfg.updateToBufDir.enable;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue