Added usage of lib.optionals and created an assersion to check the number of enabled builders

This commit is contained in:
isaacST08 2025-02-11 19:37:14 -07:00
commit d638292e77
3 changed files with 29 additions and 71 deletions

View file

@ -10,6 +10,7 @@
# The builder template
template = import ./builderTemplate.nix;
inherit (lib) optionals;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) bool package str;
in (
@ -42,11 +43,7 @@ in (
args = builderCfg: (
# Flags
(
if builderCfg.pdfOutput
then ["-pdf"]
else []
)
(optionals builderCfg.pdfOutput ["-pdf"])
# Base args
++ [
"-quiet"

View file

@ -10,6 +10,7 @@
# The builder template
template = import ./builderTemplate.nix;
inherit (lib) optionals;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum ints listOf package str;
inherit (lib.nvim.config) mkBool;
@ -133,71 +134,23 @@ in (
"%f"
]
# Flags
++ (
if builderCfg.keepIntermediates
then ["--keep-intermediates"]
else []
)
++ (
if builderCfg.keepLogs
then ["--keep-logs"]
else []
)
++ (
if builderCfg.onlyCached
then ["--only-cached"]
else []
)
++ (
if builderCfg.synctex
then ["--synctex"]
else []
)
++ (
if builderCfg.untrustedInput
then ["--untrusted"]
else []
)
++ (optionals builderCfg.keepIntermediates ["--keep-intermediates"])
++ (optionals builderCfg.keepLogs ["--keep-logs"])
++ (optionals builderCfg.onlyCached ["--only-cached"])
++ (optionals builderCfg.synctex ["--synctex"])
++ (optionals builderCfg.untrustedInput ["--untrusted"])
# Options
++ (
if builderCfg.reruns > 0
then ["--reruns" "${toString builderCfg.reruns}"]
else []
)
++ (
if builderCfg.bundle != ""
then ["--bundle" "${toString builderCfg.bundle}"]
else []
)
++ (
if builderCfg.webBundle != ""
then ["--web-bundle" "${toString builderCfg.webBundle}"]
else []
)
++ (
if builderCfg.outfmt != ""
then ["--outfmt" "${toString builderCfg.outfmt}"]
else []
)
++ (optionals (builderCfg.reruns > 0) ["--reruns" "${toString builderCfg.reruns}"])
++ (optionals (builderCfg.bundle != "") ["--bundle" "${toString builderCfg.bundle}"])
++ (optionals (builderCfg.webBundle != "") ["--web-bundle" "${toString builderCfg.webBundle}"])
++ (optionals (builderCfg.outfmt != "") ["--outfmt" "${toString builderCfg.outfmt}"])
++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths))
++ (
if builderCfg.format != ""
then ["--format" "${toString builderCfg.format}"]
else []
)
++ (
if builderCfg.color != ""
then ["--color" "${toString builderCfg.color}"]
else []
)
++ (optionals (builderCfg.format != "") ["--format" "${toString builderCfg.format}"])
++ (optionals (builderCfg.color != "") ["--color" "${toString builderCfg.color}"])
# Still options but these are not defined by builder specific options but
# instead synchronize options between the global build options and builder
# specific options
++ (
if !(elem cfg.build.pdfDirectory ["." ""])
then ["--outdir" "${cfg.build.pdfDirectory}"]
else []
)
++ (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"])
);
}
)

View file

@ -4,6 +4,7 @@
...
}: let
inherit (lib.options) mkOption;
inherit (lib.modules) mkIf;
inherit (lib.types) str nullOr;
inherit (builtins) filter isAttrs hasAttr attrNames length elemAt;
inherit (lib.nvim.config) mkBool;
@ -48,11 +49,7 @@ in {
options.vim.languages.tex.build = {
enable =
mkBool (
if enabledBuildersCount > 1
then throw "nvf-tex-language does not support having more than 1 builders enabled!"
else (enabledBuildersCount == 1)
) ''
mkBool (enabledBuildersCount == 1) ''
Whether to enable configuring the builder.
By enabling any of the builders, this option will be automatically set.
@ -106,8 +103,19 @@ in {
type = nullOr str;
default = null;
description = ''
Allows overriding the default file name of the build artifact. This setting is used to find the correct PDF file to open during forward search.
Allows overriding the default file name of the build artifact.
This setting is used to find the correct PDF file to open during forward search.
'';
};
};
config = mkIf (enabledBuildersCount > 0) {
assertions = [
{
assertion = (enabledBuildersCount < 2);
message = "The nvf-tex-language implementation does not support having more than 1 builders enabled.";
}
];
};
}