lib/options: migrate defaultNullOpts to use pluginDefault

Rename all instances where the plugin default argument is named
`default` to `pluginDefault` to avoid conflict.
This commit is contained in:
Matt Sturgeon 2024-06-14 12:25:06 +01:00
parent e51b8b9b5c
commit 5cec79e59f
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 49 additions and 49 deletions

View file

@ -9,7 +9,7 @@ let
# Render a plugin default string # Render a plugin default string
pluginDefaultText = pluginDefaultText =
let let
# Assume a string `default` is already formatted as intended, # Assume a string `pluginDefault` is already formatted as intended,
# TODO: remove this behavior so we can quote strings properly # TODO: remove this behavior so we can quote strings properly
# historically strings were the only type accepted by mkDesc. # historically strings were the only type accepted by mkDesc.
legacyRenderOptionValue = legacyRenderOptionValue =
@ -153,17 +153,13 @@ rec {
# Ensures that default is null and defaultText is not set # Ensures that default is null and defaultText is not set
convertArgs = convertArgs =
args: args:
# TODO: uncomment once all call sites migrate to `pluginDefault` assert
# assert args ? default -> abort "defaultNullOpts: unexpected argument `default`. Did you mean `pluginDefault`?"; args ? default
-> abort "defaultNullOpts: unexpected argument `default`. Did you mean `pluginDefault`?";
assert assert
args ? defaultText args ? defaultText
-> abort "defaultNullOpts: unexpected argument `defaultText`. Did you mean `pluginDefault`?"; -> abort "defaultNullOpts: unexpected argument `defaultText`. Did you mean `pluginDefault`?";
args args // { default = null; };
// {
default = null;
}
# TODO: remove once all call sites migrate to `pluginDefault`
// (optionalAttrs (args ? default) { pluginDefault = args.pluginDefault or args.default; });
in in
rec { rec {
# TODO: removed 2024-06-14; remove stub 2024-09-01 # TODO: removed 2024-06-14; remove stub 2024-09-01
@ -171,43 +167,43 @@ rec {
mkNullable' = args: mkNullOrOption' (convertArgs args); mkNullable' = args: mkNullOrOption' (convertArgs args);
mkNullable = mkNullable =
type: default: description: type: pluginDefault: description:
mkNullable' { inherit type default description; }; mkNullable' { inherit type pluginDefault description; };
mkNullableWithRaw' = mkNullableWithRaw' =
{ type, ... }@args: mkNullable' (args // { type = nixvimTypes.maybeRaw type; }); { type, ... }@args: mkNullable' (args // { type = nixvimTypes.maybeRaw type; });
mkNullableWithRaw = mkNullableWithRaw =
type: default: description: type: pluginDefault: description:
mkNullableWithRaw' { inherit type default description; }; mkNullableWithRaw' { inherit type pluginDefault description; };
mkStrLuaOr' = args: mkNullOrStrLuaOr' (convertArgs args); mkStrLuaOr' = args: mkNullOrStrLuaOr' (convertArgs args);
mkStrLuaOr = mkStrLuaOr =
type: default: description: type: pluginDefault: description:
mkStrLuaOr' { inherit type default description; }; mkStrLuaOr' { inherit type pluginDefault description; };
mkStrLuaFnOr' = args: mkNullOrStrLuaFnOr' (convertArgs args); mkStrLuaFnOr' = args: mkNullOrStrLuaFnOr' (convertArgs args);
mkStrLuaFnOr = mkStrLuaFnOr =
type: default: description: type: pluginDefault: description:
mkStrLuaFnOr' { inherit type default description; }; mkStrLuaFnOr' { inherit type pluginDefault description; };
mkLua' = args: mkNullOrLua' (convertArgs args); mkLua' = args: mkNullOrLua' (convertArgs args);
mkLua = default: description: mkLua' { inherit default description; }; mkLua = pluginDefault: description: mkLua' { inherit pluginDefault description; };
mkLuaFn' = args: mkNullOrLuaFn' (convertArgs args); mkLuaFn' = args: mkNullOrLuaFn' (convertArgs args);
mkLuaFn = default: description: mkLuaFn' { inherit default description; }; mkLuaFn = pluginDefault: description: mkLuaFn' { inherit pluginDefault description; };
mkNum' = args: mkNullableWithRaw' (args // { type = types.number; }); mkNum' = args: mkNullableWithRaw' (args // { type = types.number; });
mkNum = default: description: mkNum' { inherit default description; }; mkNum = pluginDefault: description: mkNum' { inherit pluginDefault description; };
mkInt' = args: mkNullableWithRaw' (args // { type = types.int; }); mkInt' = args: mkNullableWithRaw' (args // { type = types.int; });
mkInt = default: description: mkNum' { inherit default description; }; mkInt = pluginDefault: description: mkNum' { inherit pluginDefault description; };
# Positive: >0 # Positive: >0
mkPositiveInt' = args: mkNullableWithRaw' (args // { type = types.ints.positive; }); mkPositiveInt' = args: mkNullableWithRaw' (args // { type = types.ints.positive; });
mkPositiveInt = default: description: mkPositiveInt' { inherit default description; }; mkPositiveInt = pluginDefault: description: mkPositiveInt' { inherit pluginDefault description; };
# Unsigned: >=0 # Unsigned: >=0
mkUnsignedInt' = args: mkNullableWithRaw' (args // { type = types.ints.unsigned; }); mkUnsignedInt' = args: mkNullableWithRaw' (args // { type = types.ints.unsigned; });
mkUnsignedInt = default: description: mkUnsignedInt' { inherit default description; }; mkUnsignedInt = pluginDefault: description: mkUnsignedInt' { inherit pluginDefault description; };
mkBool' = args: mkNullableWithRaw' (args // { type = types.bool; }); mkBool' = args: mkNullableWithRaw' (args // { type = types.bool; });
mkBool = default: description: mkBool' { inherit default description; }; mkBool = pluginDefault: description: mkBool' { inherit pluginDefault description; };
mkStr' = mkStr' =
args: args:
mkNullableWithRaw' ( mkNullableWithRaw' (
@ -216,46 +212,50 @@ rec {
type = types.str; type = types.str;
} }
# TODO we should remove this once `mkDesc` no longer has a special case # TODO we should remove this once `mkDesc` no longer has a special case
// (optionalAttrs (args ? default) { default = generators.toPretty { } args.default; }) // (optionalAttrs (args ? pluginDefault) {
pluginDefault = generators.toPretty { } args.pluginDefault;
})
); );
mkStr = default: description: mkStr' { inherit default description; }; mkStr = pluginDefault: description: mkStr' { inherit pluginDefault description; };
mkAttributeSet' = args: mkNullable' (args // { type = nixvimTypes.attrs; }); mkAttributeSet' = args: mkNullable' (args // { type = nixvimTypes.attrs; });
mkAttributeSet = default: description: mkAttributeSet' { inherit default description; }; mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; };
mkListOf' = mkListOf' =
{ type, ... }@args: mkNullable' (args // { type = with nixvimTypes; listOf (maybeRaw type); }); { type, ... }@args: mkNullable' (args // { type = with nixvimTypes; listOf (maybeRaw type); });
mkListOf = mkListOf =
type: default: description: type: pluginDefault: description:
mkListOf' { inherit type default description; }; mkListOf' { inherit type pluginDefault description; };
mkAttrsOf' = mkAttrsOf' =
{ type, ... }@args: mkNullable' (args // { type = with nixvimTypes; attrsOf (maybeRaw type); }); { type, ... }@args: mkNullable' (args // { type = with nixvimTypes; attrsOf (maybeRaw type); });
mkAttrsOf = mkAttrsOf =
type: default: description: type: pluginDefault: description:
mkAttrsOf' { inherit type default description; }; mkAttrsOf' { inherit type pluginDefault description; };
mkEnum' = mkEnum' =
{ values, ... }@args: { values, ... }@args:
# `values` is a list. If `default` is present, then it is either null or one of `values` # `values` is a list. If `pluginDefault` is present, then it is either null or one of `values`
assert isList values; assert isList values;
assert args ? default -> (args.default == null || elem args.default values); assert args ? pluginDefault -> (args.pluginDefault == null || elem args.pluginDefault values);
mkNullableWithRaw' ( mkNullableWithRaw' (
(filterAttrs (n: v: n != "values") args) (filterAttrs (n: v: n != "values") args)
// { // {
type = types.enum values; type = types.enum values;
} }
# TODO we should remove this once `mkDesc` no longer has a special case # TODO we should remove this once `mkDesc` no longer has a special case
// (optionalAttrs (args ? default) { default = generators.toPretty { } args.default; }) // (optionalAttrs (args ? pluginDefault) {
pluginDefault = generators.toPretty { } args.pluginDefault;
})
); );
mkEnum = mkEnum =
values: default: description: values: pluginDefault: description:
mkEnum' { inherit values default description; }; mkEnum' { inherit values pluginDefault description; };
mkEnumFirstDefault = mkEnumFirstDefault =
values: description: values: description:
mkEnum' { mkEnum' {
inherit values description; inherit values description;
default = head values; pluginDefault = head values;
}; };
mkBorder' = mkBorder' =
@ -278,8 +278,8 @@ rec {
} }
); );
mkBorder = mkBorder =
default: name: description: pluginDefault: name: description:
mkBorder' { inherit default name description; }; mkBorder' { inherit pluginDefault name description; };
mkSeverity' = mkSeverity' =
args: args:
@ -299,7 +299,7 @@ rec {
); );
} }
); );
mkSeverity = default: description: mkSeverity' { inherit default description; }; mkSeverity = pluginDefault: description: mkSeverity' { inherit pluginDefault description; };
mkLogLevel' = mkLogLevel' =
args: args:
@ -312,7 +312,7 @@ rec {
); );
} }
); );
mkLogLevel = default: description: mkLogLevel' { inherit default description; }; mkLogLevel = pluginDefault: description: mkLogLevel' { inherit pluginDefault description; };
mkHighlight' = mkHighlight' =
{ {
@ -329,10 +329,10 @@ rec {
# FIXME `name` argument is ignored # FIXME `name` argument is ignored
# TODO deprecate in favor of `mkHighlight'`? # TODO deprecate in favor of `mkHighlight'`?
mkHighlight = mkHighlight =
default: name: description: pluginDefault: name: description:
mkHighlight' ( mkHighlight' (
{ {
inherit default; inherit pluginDefault;
} }
// (optionalAttrs (description != null && description != "") { inherit description; }) // (optionalAttrs (description != null && description != "") { inherit description; })
); );

View file

@ -6,7 +6,7 @@ with lib;
formatting = { formatting = {
command = helpers.defaultNullOpts.mkListOf' { command = helpers.defaultNullOpts.mkListOf' {
type = types.str; type = types.str;
default = null; pluginDefault = null;
description = '' description = ''
External formatting command, complete with required arguments. External formatting command, complete with required arguments.
@ -25,7 +25,7 @@ with lib;
excludedFiles = helpers.defaultNullOpts.mkListOf' { excludedFiles = helpers.defaultNullOpts.mkListOf' {
type = types.str; type = types.str;
default = [ ]; pluginDefault = [ ];
description = '' description = ''
Files to exclude from showing diagnostics. Useful for generated files. Files to exclude from showing diagnostics. Useful for generated files.
@ -38,13 +38,13 @@ with lib;
nix = { nix = {
binary = helpers.defaultNullOpts.mkStr' { binary = helpers.defaultNullOpts.mkStr' {
default = "nix"; pluginDefault = "nix";
description = "The path to the `nix` binary."; description = "The path to the `nix` binary.";
example = "/run/current-system/sw/bin/nix"; example = "/run/current-system/sw/bin/nix";
}; };
maxMemoryMB = helpers.defaultNullOpts.mkUnsignedInt' { maxMemoryMB = helpers.defaultNullOpts.mkUnsignedInt' {
default = 2560; pluginDefault = 2560;
example = 1024; example = 1024;
description = '' description = ''
The heap memory limit in MiB for `nix` evaluation. The heap memory limit in MiB for `nix` evaluation.
@ -72,7 +72,7 @@ with lib;
''; '';
nixpkgsInputName = helpers.defaultNullOpts.mkStr' { nixpkgsInputName = helpers.defaultNullOpts.mkStr' {
default = "nixpkgs"; pluginDefault = "nixpkgs";
example = "nixos"; example = "nixos";
description = '' description = ''
The input name of nixpkgs for NixOS options evaluation. The input name of nixpkgs for NixOS options evaluation.

View file

@ -14,7 +14,7 @@ with lib;
See [the source](https://github.com/nix-community/nixd/blob/main/libnixf/include/nixf/Basic/DiagnosticKinds.inc) See [the source](https://github.com/nix-community/nixd/blob/main/libnixf/include/nixf/Basic/DiagnosticKinds.inc)
for available diagnostics. for available diagnostics.
''; '';
default = [ ]; pluginDefault = [ ];
example = [ "sema-escaping-with" ]; example = [ "sema-escaping-with" ];
}; };
}; };