Skip to content

Commit

Permalink
lib/options: migrate defaultNullOpts to use pluginDefault
Browse files Browse the repository at this point in the history
Rename all instances where the plugin default argument is named
`default` to `pluginDefault` to avoid conflict.
  • Loading branch information
MattSturgeon committed Jun 14, 2024
1 parent e51b8b9 commit 5cec79e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
86 changes: 43 additions & 43 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
# Render a plugin default string
pluginDefaultText =
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
# historically strings were the only type accepted by mkDesc.
legacyRenderOptionValue =
Expand Down Expand Up @@ -153,61 +153,57 @@ rec {
# Ensures that default is null and defaultText is not set
convertArgs =
args:
# TODO: uncomment once all call sites migrate to `pluginDefault`
# assert args ? default -> abort "defaultNullOpts: unexpected argument `default`. Did you mean `pluginDefault`?";
assert
args ? default
-> abort "defaultNullOpts: unexpected argument `default`. Did you mean `pluginDefault`?";
assert
args ? defaultText
-> abort "defaultNullOpts: unexpected argument `defaultText`. Did you mean `pluginDefault`?";
args
// {
default = null;
}
# TODO: remove once all call sites migrate to `pluginDefault`
// (optionalAttrs (args ? default) { pluginDefault = args.pluginDefault or args.default; });
args // { default = null; };
in
rec {
# TODO: removed 2024-06-14; remove stub 2024-09-01
mkDesc = abort "mkDesc has been removed. Use the `pluginDefault` argument or `helpers.pluginDefaultText`.";

mkNullable' = args: mkNullOrOption' (convertArgs args);
mkNullable =
type: default: description:
mkNullable' { inherit type default description; };
type: pluginDefault: description:
mkNullable' { inherit type pluginDefault description; };

mkNullableWithRaw' =
{ type, ... }@args: mkNullable' (args // { type = nixvimTypes.maybeRaw type; });
mkNullableWithRaw =
type: default: description:
mkNullableWithRaw' { inherit type default description; };
type: pluginDefault: description:
mkNullableWithRaw' { inherit type pluginDefault description; };

mkStrLuaOr' = args: mkNullOrStrLuaOr' (convertArgs args);
mkStrLuaOr =
type: default: description:
mkStrLuaOr' { inherit type default description; };
type: pluginDefault: description:
mkStrLuaOr' { inherit type pluginDefault description; };

mkStrLuaFnOr' = args: mkNullOrStrLuaFnOr' (convertArgs args);
mkStrLuaFnOr =
type: default: description:
mkStrLuaFnOr' { inherit type default description; };
type: pluginDefault: description:
mkStrLuaFnOr' { inherit type pluginDefault description; };

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 = default: description: mkLuaFn' { inherit default description; };
mkLuaFn = pluginDefault: description: mkLuaFn' { inherit pluginDefault description; };

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 = default: description: mkNum' { inherit default description; };
mkInt = pluginDefault: description: mkNum' { inherit pluginDefault description; };
# Positive: >0
mkPositiveInt' = args: mkNullableWithRaw' (args // { type = types.ints.positive; });
mkPositiveInt = default: description: mkPositiveInt' { inherit default description; };
mkPositiveInt = pluginDefault: description: mkPositiveInt' { inherit pluginDefault description; };
# Unsigned: >=0
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 = default: description: mkBool' { inherit default description; };
mkBool = pluginDefault: description: mkBool' { inherit pluginDefault description; };
mkStr' =
args:
mkNullableWithRaw' (
Expand All @@ -216,46 +212,50 @@ rec {
type = types.str;
}
# 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 = default: description: mkAttributeSet' { inherit default description; };
mkAttributeSet = pluginDefault: description: mkAttributeSet' { inherit pluginDefault description; };

mkListOf' =
{ type, ... }@args: mkNullable' (args // { type = with nixvimTypes; listOf (maybeRaw type); });
mkListOf =
type: default: description:
mkListOf' { inherit type default description; };
type: pluginDefault: description:
mkListOf' { inherit type pluginDefault description; };

mkAttrsOf' =
{ type, ... }@args: mkNullable' (args // { type = with nixvimTypes; attrsOf (maybeRaw type); });
mkAttrsOf =
type: default: description:
mkAttrsOf' { inherit type default description; };
type: pluginDefault: description:
mkAttrsOf' { inherit type pluginDefault description; };

mkEnum' =
{ 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 args ? default -> (args.default == null || elem args.default values);
assert args ? pluginDefault -> (args.pluginDefault == null || elem args.pluginDefault values);
mkNullableWithRaw' (
(filterAttrs (n: v: n != "values") args)
// {
type = types.enum values;
}
# 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 =
values: default: description:
mkEnum' { inherit values default description; };
values: pluginDefault: description:
mkEnum' { inherit values pluginDefault description; };
mkEnumFirstDefault =
values: description:
mkEnum' {
inherit values description;
default = head values;
pluginDefault = head values;
};

mkBorder' =
Expand All @@ -278,8 +278,8 @@ rec {
}
);
mkBorder =
default: name: description:
mkBorder' { inherit default name description; };
pluginDefault: name: description:
mkBorder' { inherit pluginDefault name description; };

mkSeverity' =
args:
Expand All @@ -299,7 +299,7 @@ rec {
);
}
);
mkSeverity = default: description: mkSeverity' { inherit default description; };
mkSeverity = pluginDefault: description: mkSeverity' { inherit pluginDefault description; };

mkLogLevel' =
args:
Expand All @@ -312,7 +312,7 @@ rec {
);
}
);
mkLogLevel = default: description: mkLogLevel' { inherit default description; };
mkLogLevel = pluginDefault: description: mkLogLevel' { inherit pluginDefault description; };

mkHighlight' =
{
Expand All @@ -329,10 +329,10 @@ rec {
# FIXME `name` argument is ignored
# TODO deprecate in favor of `mkHighlight'`?
mkHighlight =
default: name: description:
pluginDefault: name: description:
mkHighlight' (
{
inherit default;
inherit pluginDefault;
}
// (optionalAttrs (description != null && description != "") { inherit description; })
);
Expand Down
10 changes: 5 additions & 5 deletions plugins/lsp/language-servers/nil-ls-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ with lib;
formatting = {
command = helpers.defaultNullOpts.mkListOf' {
type = types.str;
default = null;
pluginDefault = null;
description = ''
External formatting command, complete with required arguments.
Expand All @@ -25,7 +25,7 @@ with lib;

excludedFiles = helpers.defaultNullOpts.mkListOf' {
type = types.str;
default = [ ];
pluginDefault = [ ];
description = ''
Files to exclude from showing diagnostics. Useful for generated files.
Expand All @@ -38,13 +38,13 @@ with lib;

nix = {
binary = helpers.defaultNullOpts.mkStr' {
default = "nix";
pluginDefault = "nix";
description = "The path to the `nix` binary.";
example = "/run/current-system/sw/bin/nix";
};

maxMemoryMB = helpers.defaultNullOpts.mkUnsignedInt' {
default = 2560;
pluginDefault = 2560;
example = 1024;
description = ''
The heap memory limit in MiB for `nix` evaluation.
Expand Down Expand Up @@ -72,7 +72,7 @@ with lib;
'';

nixpkgsInputName = helpers.defaultNullOpts.mkStr' {
default = "nixpkgs";
pluginDefault = "nixpkgs";
example = "nixos";
description = ''
The input name of nixpkgs for NixOS options evaluation.
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsp/language-servers/nixd-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with lib;
See [the source](https://github.com/nix-community/nixd/blob/main/libnixf/include/nixf/Basic/DiagnosticKinds.inc)
for available diagnostics.
'';
default = [ ];
pluginDefault = [ ];
example = [ "sema-escaping-with" ];
};
};
Expand Down

0 comments on commit 5cec79e

Please sign in to comment.