From d638292e774ad6ab8dbc2b391cecf2da72c8256a Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 19:37:14 -0700 Subject: [PATCH] Added usage of lib.optionals and created an assersion to check the number of enabled builders --- .../languages/tex/build/builders/latexmk.nix | 7 +- .../languages/tex/build/builders/tectonic.nix | 73 ++++--------------- .../plugins/languages/tex/build/default.nix | 20 +++-- 3 files changed, 29 insertions(+), 71 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index 4d024eb3..c1f17917 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -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" diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 1b131b33..7513350d 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -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}"]) ); } ) diff --git a/modules/plugins/languages/tex/build/default.nix b/modules/plugins/languages/tex/build/default.nix index fe07775b..78f13588 100644 --- a/modules/plugins/languages/tex/build/default.nix +++ b/modules/plugins/languages/tex/build/default.nix @@ -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."; + } + ]; + }; }