mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-12 10:14:31 +02:00
core: show warnings for deprecated or changed options (#129)
* moved helpers to lib folder * Created proxy file for helpers.nix * wrappers: removed code duplication * null-ls: fix wrong name of variable * added warnings module * Added assertions * bufferline: deprecated option * nvim-tree: renamed options * Fixed mkRenamedOption * Bufferline: added new options * Fixed deprecated option Co-authored-by: Pedro Alves <pta2002@pta2002.com>
This commit is contained in:
parent
5fac9be0ab
commit
63c256dc3d
10 changed files with 369 additions and 206 deletions
81
lib/option-warnings.nix
Normal file
81
lib/option-warnings.nix
Normal file
|
@ -0,0 +1,81 @@
|
|||
{ 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 =
|
||||
{ option # an array of the path to the option
|
||||
, alternative ? null
|
||||
, message ? null
|
||||
, visible ? false
|
||||
}:
|
||||
{ options, config, ... }:
|
||||
let
|
||||
fromOpt = getAttrFromPath option options;
|
||||
fromValue = getAttrFromPath option config;
|
||||
fullMessage = "The option `${showOption option}` has been deprecated, but might still work." +
|
||||
(optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.") +
|
||||
(optionalString (message != null) " Message: ${message}");
|
||||
in
|
||||
{
|
||||
config = mkIf (fromOpt.isDefined && fromValue != fromOpt.default) {
|
||||
warnings = [
|
||||
("Nixvim: ${fullMessage}")
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
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 && fromOpt.isDefined) [ "Nixvim: ${message}" ];
|
||||
}
|
||||
(mkAliasAndWrapDefinitions (setAttrByPath newOption) fromOpt)
|
||||
];
|
||||
};
|
||||
|
||||
mkAliasOption = option: newOption: mkRenamedOption {
|
||||
inherit option newOption;
|
||||
visible = true;
|
||||
warn = false;
|
||||
overrideDescription = "Alias of ${showOption newOption}";
|
||||
};
|
||||
|
||||
# TODO:
|
||||
# mkRemovedOption =
|
||||
# { option
|
||||
# , visible ? false
|
||||
# }:
|
||||
# { options, ... }:
|
||||
# {
|
||||
# options = { };
|
||||
# config = { };
|
||||
# };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue