From ac75542243a68aaaaf1bb7f4854c241699bfa592 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 19:26:51 -0700 Subject: [PATCH 01/65] Created tex language options --- modules/plugins/languages/default.nix | 1 + modules/plugins/languages/tex.nix | 309 ++++++++++++++++++++++++++ 2 files changed, 310 insertions(+) create mode 100644 modules/plugins/languages/tex.nix diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index fd45758f..5f66ead5 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -38,6 +38,7 @@ in { ./svelte.nix ./tailwind.nix ./terraform.nix + ./tex.nix ./ts.nix ./typst.nix ./zig.nix diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix new file mode 100644 index 00000000..b98ea26e --- /dev/null +++ b/modules/plugins/languages/tex.nix @@ -0,0 +1,309 @@ +# TODO: +# - Add Texlab LSP settings: +# - chktex +# - diagnosticsDelay +# - diagnostics +# - symbols +# - formatterLineLength +# - bibtexFormatter +# - latexFormatter +# - latexindent +# - completion +# - inlayHints +# - experimental + +{ + config, + pkgs, + lib, + ... +}: +let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge listOf; + inherit (lib.types) package str bool; + inherit (lib.nvim.types) mkGrammarOption; + inherit (builtins) any attrValues; + + cfg = config.vim.languages.tex; +in +{ + options.vim.languages.tex = { + enable = mkEnableOption "Tex support"; + + # Treesitter options for latex and bibtex flavours of tex. + treesitter = { + latex = { + enable = mkEnableOption "Latex treesitter" // { + default = config.vim.languages.enableTreesitter; + }; + package = mkGrammarOption pkgs "latex"; + }; + bibtex = { + enable = mkEnableOption "Bibtex treesitter" // { + default = config.vim.languages.enableTreesitter; + }; + package = mkGrammarOption pkgs "bibtex"; + }; + }; + + # LSP options + # Because tex LSPs also including building/compiling tex, they have + # more options that are only specific to them and thus it makes + # more sense to group one into its own group of options. + # + # Each lsp group must have an enable option of its own. + lsp = { + texlab = { + enable = mkEnableOption "Tex LSP support (texlab)" // { + default = config.vim.languages.enableLSP; + }; + + package = mkOption { + type = package; + default = pkgs.texlab; + description = "texlab package"; + }; + + build = { + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "build/compiler package"; + }; + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + args = mkOption { + type = listOf str; + default = [ + "-X" + "compile" + "%f" + "--synctex" + "--keep-logs" + "--keep-intermediates" + ]; + description = '' + Defines additional arguments that are passed to the configured LaTeX build tool. + Note that flags and their arguments need to be separate elements in this array. + To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + The placeholder `%f` will be replaced by the server. + + Placeholders: + - `%f`: The path of the TeX file to compile. + ''; + }; + forwardSearchAfter = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to execute a forward search after a build."; + }; + onSave = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to compile the project after saving a file."; + }; + useFileList = mkOption { + type = bool; + default = false; + description = '' + When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + + Note that enabling this property might have an impact on performance. + ''; + }; + auxDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the .aux files. + Note that you need to set the aux directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + logDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the build log files. + Note that you need to change the output directory in your build arguments too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + pdfDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the output files. + Note that you need to set the output directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + filename = mkOption { + type = 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. + ''; + }; + }; + + forwardSearch = { + enable = mkOption { + type = bool; + default = false; + example = true; + description = '' + Whether to enable forward search. + + Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + + For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + Note this is not all the options, but can act as a guide to help you allong with custom configs. + ''; + }; + package = mkOption { + type = package; + default = pkgs.okular; + description = '' + The package to use as your PDF viewer. + This viewer needs to support Synctex. + ''; + }; + executable = mkOption { + type = str; + default = "okular"; + description = '' + Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + ''; + }; + args = mkOption { + type = listOf str; + default = [ + "--unique" + "file:%p#src:%l%f" + ]; + description = '' + Defines additional arguments that are passed to the configured previewer to perform the forward search. + The placeholders %f, %p, %l will be replaced by the server. + + Placeholders: + - %f: The path of the current TeX file. + - %p: The path of the current PDF file. + - %l: The current line number. + ''; + }; + + }; + + extraLuaSettings = mkOption { + type = str; + default = ""; + example = '' + formatterLineLength = 80, + ''; + description = '' + For any options that do not have options provided through nvf this can be used to add them. + Options already declared in nvf config will NOT be overridden. + + Options will be placed in: + ``` + lspconfig.texlab.setup { + settings = { + texlab = { + ... + + ... + + } + } + } + ``` + ''; + }; + }; + + # Add other LSPs here + + }; + }; + + config = mkIf cfg.enable (mkMerge [ + + # Treesitter + (mkIf cfg.treesitter.latex.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [ cfg.treesitter.latex.package ]; + }) + (mkIf cfg.treesitter.bibtex.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [ cfg.treesitter.bibtex.package ]; + }) + + # LSP + (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( + { + vim.lsp.lspconfig.enable = true; # Enable lspconfig when any of the lsps are enabled + } + // (mkMerge [ + + # Texlab + ( + let + tl = cfg.lsp.texlab; + build = tl.build; + listToLua = + list: nullOnEmpty: + let + inherit (builtins) + length + concatStringsSep + map + toString + ; + in + if length list == 0 then + if nullOnEmpty then "null" else "{ }" + else + "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + in + (mkIf tl.enable { + vim.lsp.lspconfig.sources.texlab = '' + lspconfig.texlab.setup { + settings = { + texlab = { + build = { + executable = "${build.package}/bin/${build.executable}", + args = ${listToLua build.args false}, + forwardSearchAfter = ${build.forwardSearchAfter}, + onSave = ${build.onSave}, + useFileList = ${build.useFileList}, + auxDirectory = "${build.auxDirectroy}", + logDirectory = "${build.logDirectroy}", + pdfDirectory = "${build.pdfDirectroy}", + ${if build.filename != null then ''filename = "${build.filename}",'' else ""} + }, + forwardSearch = { + executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", + args = ${listToLua tl.forwardSearch.args true} + }, + ${tl.extraLuaSettings} + } + } + } + ''; + }) + ) + + # Add other LSPs here + ]) + )) + + ]); +} From 7dceb8b0c095fdcabbe45518283a5667f136a3e6 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 19:56:41 -0700 Subject: [PATCH 02/65] Fix import on the wrong line --- modules/plugins/languages/tex.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index b98ea26e..dd0f7910 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -20,8 +20,8 @@ }: let inherit (lib.options) mkEnableOption mkOption; - inherit (lib.modules) mkIf mkMerge listOf; - inherit (lib.types) package str bool; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.types) package str bool listOf; inherit (lib.nvim.types) mkGrammarOption; inherit (builtins) any attrValues; From d42896be4a146dc4e86ca306f331f44724a4add8 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 20:01:08 -0700 Subject: [PATCH 03/65] Added toString functions on Texlab LSP source booleans and other mapped values --- modules/plugins/languages/tex.nix | 33 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index dd0f7910..90363bd8 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -21,7 +21,12 @@ let inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) package str bool listOf; + inherit (lib.types) + package + str + bool + listOf + ; inherit (lib.nvim.types) mkGrammarOption; inherit (builtins) any attrValues; @@ -256,18 +261,16 @@ in # Texlab ( let + inherit (builtins) + length + concatStringsSep + map + toString + ; tl = cfg.lsp.texlab; build = tl.build; listToLua = list: nullOnEmpty: - let - inherit (builtins) - length - concatStringsSep - map - toString - ; - in if length list == 0 then if nullOnEmpty then "null" else "{ }" else @@ -281,12 +284,12 @@ in build = { executable = "${build.package}/bin/${build.executable}", args = ${listToLua build.args false}, - forwardSearchAfter = ${build.forwardSearchAfter}, - onSave = ${build.onSave}, - useFileList = ${build.useFileList}, - auxDirectory = "${build.auxDirectroy}", - logDirectory = "${build.logDirectroy}", - pdfDirectory = "${build.pdfDirectroy}", + forwardSearchAfter = ${toString build.forwardSearchAfter}, + onSave = ${toString build.onSave}, + useFileList = ${toString build.useFileList}, + auxDirectory = "${toString build.auxDirectroy}", + logDirectory = "${toString build.logDirectroy}", + pdfDirectory = "${toString build.pdfDirectroy}", ${if build.filename != null then ''filename = "${build.filename}",'' else ""} }, forwardSearch = { From 286f292127b4fd47f7dc6cde06cc77b956958eaf Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 20:03:40 -0700 Subject: [PATCH 04/65] Fixed typo --- modules/plugins/languages/tex.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 90363bd8..80b7b7de 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -287,9 +287,9 @@ in forwardSearchAfter = ${toString build.forwardSearchAfter}, onSave = ${toString build.onSave}, useFileList = ${toString build.useFileList}, - auxDirectory = "${toString build.auxDirectroy}", - logDirectory = "${toString build.logDirectroy}", - pdfDirectory = "${toString build.pdfDirectroy}", + auxDirectory = "${toString build.auxDirectory}", + logDirectory = "${toString build.logDirectory}", + pdfDirectory = "${toString build.pdfDirectory}", ${if build.filename != null then ''filename = "${build.filename}",'' else ""} }, forwardSearch = { From 4fbc78cd42e324e404005fc8a596ba27063efec7 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 20:11:32 -0700 Subject: [PATCH 05/65] Created function to simplify converting a string into lua format and removed null default values --- modules/plugins/languages/tex.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 80b7b7de..409551a6 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -152,7 +152,7 @@ in }; filename = mkOption { type = str; - default = null; + default = ""; 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. ''; @@ -269,12 +269,16 @@ in ; tl = cfg.lsp.texlab; build = tl.build; + listToLua = list: nullOnEmpty: if length list == 0 then if nullOnEmpty then "null" else "{ }" else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + + stringToLua = + string: nullOnEmpty: if string == "" then if nullOnEmpty then "null" else "" else ''"${string}"''; in (mkIf tl.enable { vim.lsp.lspconfig.sources.texlab = '' @@ -287,9 +291,9 @@ in forwardSearchAfter = ${toString build.forwardSearchAfter}, onSave = ${toString build.onSave}, useFileList = ${toString build.useFileList}, - auxDirectory = "${toString build.auxDirectory}", - logDirectory = "${toString build.logDirectory}", - pdfDirectory = "${toString build.pdfDirectory}", + auxDirectory = ${stringToLua build.auxDirectory true}, + logDirectory = ${stringToLua build.logDirectory true}, + pdfDirectory = ${stringToLua build.pdfDirectory true}, ${if build.filename != null then ''filename = "${build.filename}",'' else ""} }, forwardSearch = { From 186b6fd8c19b26432b7d1c9fb8ce6f7ce028dcaa Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 20:20:56 -0700 Subject: [PATCH 06/65] Fixed weird nix boolean toString implementation --- modules/plugins/languages/tex.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 409551a6..f09c02d4 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -279,6 +279,9 @@ in stringToLua = string: nullOnEmpty: if string == "" then if nullOnEmpty then "null" else "" else ''"${string}"''; + + boolToLua = + boolean: if boolean then "true" else "false"; in (mkIf tl.enable { vim.lsp.lspconfig.sources.texlab = '' @@ -288,9 +291,9 @@ in build = { executable = "${build.package}/bin/${build.executable}", args = ${listToLua build.args false}, - forwardSearchAfter = ${toString build.forwardSearchAfter}, - onSave = ${toString build.onSave}, - useFileList = ${toString build.useFileList}, + forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, + onSave = ${boolToLua build.onSave}, + useFileList = ${boolToLua build.useFileList}, auxDirectory = ${stringToLua build.auxDirectory true}, logDirectory = ${stringToLua build.logDirectory true}, pdfDirectory = ${stringToLua build.pdfDirectory true}, From 8a2a635fc48fc9e4269c1b05435f612ddfe3a8db Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 20:30:55 -0700 Subject: [PATCH 07/65] Changed texlab lsp config build.filename to use stringToLua function --- modules/plugins/languages/tex.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index f09c02d4..48e3357a 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -297,7 +297,7 @@ in auxDirectory = ${stringToLua build.auxDirectory true}, logDirectory = ${stringToLua build.logDirectory true}, pdfDirectory = ${stringToLua build.pdfDirectory true}, - ${if build.filename != null then ''filename = "${build.filename}",'' else ""} + filename = ${stringToLua build.filename true}, }, forwardSearch = { executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", From 52d36c0c2c6ae3090f5458998fb8d8097d482d14 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 18 Jan 2025 21:03:43 -0700 Subject: [PATCH 08/65] Added tex to the languages list --- docs/manual/configuring/languages.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/manual/configuring/languages.md b/docs/manual/configuring/languages.md index f956a0e3..0b940582 100644 --- a/docs/manual/configuring/languages.md +++ b/docs/manual/configuring/languages.md @@ -79,6 +79,8 @@ languages have sections under the `vim.languages` attribute. [vim.languages.tailwind.enable](./options.html#option-vim-languages-tailwind-enable) - Terraform: [vim.languages.terraform.enable](./options.html#option-vim-languages-terraform-enable) +- Tex: + [vim.languages.tex.enable](./options.html#option-vim-languages-tex-enable) - Typst: [vim.languages.typst.enable](./options.html#option-vim-languages-typst-enable) - Vala: From 25e2cfa49bf8c69eda881655e1fc3ad0d32c6686 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 19 Jan 2025 11:06:22 -0700 Subject: [PATCH 09/65] Fixed texlab needing to be installed globally to be able to use the lsp --- modules/plugins/languages/tex.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 48e3357a..57b3be97 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -280,12 +280,12 @@ in stringToLua = string: nullOnEmpty: if string == "" then if nullOnEmpty then "null" else "" else ''"${string}"''; - boolToLua = - boolean: if boolean then "true" else "false"; + boolToLua = boolean: if boolean then "true" else "false"; in (mkIf tl.enable { vim.lsp.lspconfig.sources.texlab = '' lspconfig.texlab.setup { + cmd = { "${tl.package}/bin/texlab" }, settings = { texlab = { build = { From 60fe055375035130a283fc74d9f0d3d21143a7a2 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 19 Jan 2025 15:54:54 -0700 Subject: [PATCH 10/65] Added support for setting the g:tex_flavor option --- modules/plugins/languages/tex.nix | 65 ++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 57b3be97..9b611c99 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -11,7 +11,6 @@ # - completion # - inlayHints # - experimental - { config, pkgs, @@ -22,13 +21,20 @@ let inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.types) - package - str bool listOf + package + str ; inherit (lib.nvim.types) mkGrammarOption; - inherit (builtins) any attrValues; + inherit (builtins) + any + attrValues + concatStringsSep + length + map + toString + ; cfg = config.vim.languages.tex; in @@ -204,7 +210,6 @@ in - %l: The current line number. ''; }; - }; extraLuaSettings = mkOption { @@ -235,12 +240,49 @@ in }; # Add other LSPs here + }; + extraOpts = { + texFlavor = { + enable = mkOption { + type = bool; + default = false; + example = true; + description = '' + Whether to set the vim.g.tex_flavor (g:tex_flavor) option in your lua config. + + When opening a .tex file vim will try to automatically try to determine the file type from + the three options: plaintex (for plain TeX), context (for ConTeXt), or tex (for LaTeX). + This can either be done by a indicator line of the form `%&` on the first line or + if absent vim will search the file for keywords to try and determine the filetype. + If no filetype can be determined automatically then by default it will fallback to plaintex. + + This option will enable setting the tex flavor in your lua config and you can set its value + useing the `vim.languages.tex.lsp.extraOpts.texFlavor.flavor = ` in your nvf config. + + Setting this option to `false` will omit the `vim.g.tex_flavor = ` line from your lua + config entirely (unless you manually set it elsewhere of course). + ''; + }; + flavor = mkOption { + type = str; + default = "plaintex"; + example = "tex"; + description = '' + The flavor to set as a fallback for when vim cannot automatically determine the tex flavor when + opening a .tex document. + + The options are: plaintex (for plain TeX), context (for ConTeXt), or tex (for LaTeX). + + This can be particularly useful for when using `vim.utility.new-file-template` options for + creating templates when no context has yet been added to a new file. + ''; + }; + }; }; }; config = mkIf cfg.enable (mkMerge [ - # Treesitter (mkIf cfg.treesitter.latex.enable { vim.treesitter.enable = true; @@ -257,16 +299,9 @@ in vim.lsp.lspconfig.enable = true; # Enable lspconfig when any of the lsps are enabled } // (mkMerge [ - # Texlab ( let - inherit (builtins) - length - concatStringsSep - map - toString - ; tl = cfg.lsp.texlab; build = tl.build; @@ -315,5 +350,9 @@ in ]) )) + # Extra Lua config options + (mkIf cfg.extraOpts.texFlavor.enable { + vim.globals.tex_flavor = "${cfg.extraOpts.texFlavor.flavor}"; + }) ]); } From 187bf3ef259b6ba2d4b9bc1833b2f00e6df3c57c Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 19 Jan 2025 16:05:26 -0700 Subject: [PATCH 11/65] Switched to Alejandra formatting style --- modules/plugins/languages/tex.nix | 63 ++++++++++++++++--------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 9b611c99..6fb6e845 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -16,18 +16,19 @@ pkgs, lib, ... -}: -let +}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) + inherit + (lib.types) bool listOf package str ; inherit (lib.nvim.types) mkGrammarOption; - inherit (builtins) + inherit + (builtins) any attrValues concatStringsSep @@ -37,23 +38,18 @@ let ; cfg = config.vim.languages.tex; -in -{ +in { options.vim.languages.tex = { enable = mkEnableOption "Tex support"; # Treesitter options for latex and bibtex flavours of tex. treesitter = { latex = { - enable = mkEnableOption "Latex treesitter" // { - default = config.vim.languages.enableTreesitter; - }; + enable = mkEnableOption "Latex treesitter" // { default = config.vim.languages.enableTreesitter; }; package = mkGrammarOption pkgs "latex"; }; bibtex = { - enable = mkEnableOption "Bibtex treesitter" // { - default = config.vim.languages.enableTreesitter; - }; + enable = mkEnableOption "Bibtex treesitter" // { default = config.vim.languages.enableTreesitter; }; package = mkGrammarOption pkgs "bibtex"; }; }; @@ -66,9 +62,7 @@ in # Each lsp group must have an enable option of its own. lsp = { texlab = { - enable = mkEnableOption "Tex LSP support (texlab)" // { - default = config.vim.languages.enableLSP; - }; + enable = mkEnableOption "Tex LSP support (texlab)" // { default = config.vim.languages.enableLSP; }; package = mkOption { type = package; @@ -286,18 +280,16 @@ in # Treesitter (mkIf cfg.treesitter.latex.enable { vim.treesitter.enable = true; - vim.treesitter.grammars = [ cfg.treesitter.latex.package ]; + vim.treesitter.grammars = [cfg.treesitter.latex.package]; }) (mkIf cfg.treesitter.bibtex.enable { vim.treesitter.enable = true; - vim.treesitter.grammars = [ cfg.treesitter.bibtex.package ]; + vim.treesitter.grammars = [cfg.treesitter.bibtex.package]; }) # LSP (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( - { - vim.lsp.lspconfig.enable = true; # Enable lspconfig when any of the lsps are enabled - } + { vim.lsp.lspconfig.enable = true; } # Enable lspconfig when any of the lsps are enabled // (mkMerge [ # Texlab ( @@ -305,19 +297,28 @@ in tl = cfg.lsp.texlab; build = tl.build; - listToLua = - list: nullOnEmpty: - if length list == 0 then - if nullOnEmpty then "null" else "{ }" - else - "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + listToLua = list: nullOnEmpty: + if length list == 0 + then + if nullOnEmpty + then "null" + else "{ }" + else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; - stringToLua = - string: nullOnEmpty: if string == "" then if nullOnEmpty then "null" else "" else ''"${string}"''; + stringToLua = string: nullOnEmpty: + if string == "" + then + if nullOnEmpty + then "null" + else "" + else ''"${string}"''; - boolToLua = boolean: if boolean then "true" else "false"; - in - (mkIf tl.enable { + boolToLua = boolean: + if boolean + then "true" + else "false"; + + in (mkIf tl.enable { vim.lsp.lspconfig.sources.texlab = '' lspconfig.texlab.setup { cmd = { "${tl.package}/bin/texlab" }, From e78b4ffe072ea8e88088365d9873693ba5e312bb Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 16:08:31 -0700 Subject: [PATCH 13/65] Starting modularizing tex.nix into smaller sections --- modules/plugins/languages/default.nix | 2 +- .../languages/{tex.nix => tex/default.nix} | 45 ++++++++++--------- modules/plugins/languages/tex/treesitter.nix | 39 ++++++++++++++++ 3 files changed, 65 insertions(+), 21 deletions(-) rename modules/plugins/languages/{tex.nix => tex/default.nix} (96%) create mode 100644 modules/plugins/languages/tex/treesitter.nix diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 5f66ead5..5b55224c 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -38,7 +38,7 @@ in { ./svelte.nix ./tailwind.nix ./terraform.nix - ./tex.nix + ./tex ./ts.nix ./typst.nix ./zig.nix diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex/default.nix similarity index 96% rename from modules/plugins/languages/tex.nix rename to modules/plugins/languages/tex/default.nix index e39a4be3..54811783 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex/default.nix @@ -142,20 +142,25 @@ custom = buildConfig: buildConfig.custom.args; }; in { + + imports = [ + ./treesitter.nix + ]; + options.vim.languages.tex = { enable = mkEnableOption "Tex support"; - # Treesitter options for latex and bibtex flavours of tex. - treesitter = { - latex = { - enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; - package = mkGrammarOption pkgs "latex"; - }; - bibtex = { - enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; - package = mkGrammarOption pkgs "bibtex"; - }; - }; + # # Treesitter options for latex and bibtex flavours of tex. + # treesitter = { + # latex = { + # enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; + # package = mkGrammarOption pkgs "latex"; + # }; + # bibtex = { + # enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; + # package = mkGrammarOption pkgs "bibtex"; + # }; + # }; # LSP options # Because tex LSPs also including building/compiling tex, they have @@ -485,15 +490,15 @@ in { }; config = mkIf cfg.enable (mkMerge [ - # Treesitter - (mkIf cfg.treesitter.latex.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.latex.package]; - }) - (mkIf cfg.treesitter.bibtex.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.bibtex.package]; - }) + # # Treesitter + # (mkIf cfg.treesitter.latex.enable { + # vim.treesitter.enable = true; + # vim.treesitter.grammars = [cfg.treesitter.latex.package]; + # }) + # (mkIf cfg.treesitter.bibtex.enable { + # vim.treesitter.enable = true; + # vim.treesitter.grammars = [cfg.treesitter.bibtex.package]; + # }) # LSP (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( diff --git a/modules/plugins/languages/tex/treesitter.nix b/modules/plugins/languages/tex/treesitter.nix new file mode 100644 index 00000000..3b70165e --- /dev/null +++ b/modules/plugins/languages/tex/treesitter.nix @@ -0,0 +1,39 @@ +{ + config, + pkgs, + lib, + ... +}: +let + inherit (lib.options) mkEnableOption; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.types) mkGrammarOption; + + cfg = config.vim.languages.tex; + + mkEnableTreesitterOption = + description: mkEnableOption description // { default = config.vim.languages.enableTreesitter; }; +in +{ + options.vim.languages.tex.treesitter = { + latex = { + enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; + package = mkGrammarOption pkgs "latex"; + }; + bibtex = { + enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; + package = mkGrammarOption pkgs "bibtex"; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.latex.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [ cfg.treesitter.latex.package ]; + }) + (mkIf cfg.treesitter.bibtex.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [ cfg.treesitter.bibtex.package ]; + }) + ]); +} From 8f042cedca470e8f69147702fafd21c5c1df0904 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 16:34:57 -0700 Subject: [PATCH 14/65] Moved lsp config into its own module --- modules/plugins/languages/tex/default.nix | 965 +++++++++--------- modules/plugins/languages/tex/lsp/default.nix | 528 ++++++++++ 2 files changed, 1011 insertions(+), 482 deletions(-) create mode 100644 modules/plugins/languages/tex/lsp/default.nix diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 54811783..116403d1 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -52,99 +52,100 @@ cfg = config.vim.languages.tex; # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); - mkEnableTreesitterOption = mkEnableDefaultOption config.vim.languages.enableTreesitter; - mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; + # mkEnableDefaultOption = default: description: (mkOption { + # type = bool; + # default = default; + # example = !default; + # description = description; + # }); + # mkEnableTreesitterOption = mkEnableDefaultOption config.vim.languages.enableTreesitter; + # mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; - # --- Arg Collation Functions -- - collateArgs.lsp.texlab.build = { - tectonic = buildConfig: let - selfConfig = buildConfig.tectonic; - in ( - # Base args - [ - "-X" - "compile" - "%f" - ] - # Flags - ++ ( - if selfConfig.keepIntermediates - then ["--keep-intermediates"] - else [] - ) - ++ ( - if selfConfig.keepLogs - then ["--keep-logs"] - else [] - ) - ++ ( - if selfConfig.onlyCached - then ["--only-cached"] - else [] - ) - ++ ( - if selfConfig.synctex - then ["--synctex"] - else [] - ) - ++ ( - if selfConfig.untrustedInput - then ["--untrusted"] - else [] - ) - # Options - ++ ( - if selfConfig.reruns > 0 - then ["--reruns" "${toString selfConfig.reruns}"] - else [] - ) - ++ ( - if selfConfig.bundle != "" - then ["--bundle" "${toString selfConfig.bundle}"] - else [] - ) - ++ ( - if selfConfig.webBundle != "" - then ["--web-bundle" "${toString selfConfig.webBundle}"] - else [] - ) - ++ ( - if selfConfig.outfmt != "" - then ["--outfmt" "${toString selfConfig.outfmt}"] - else [] - ) - ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - ++ ( - if selfConfig.format != "" - then ["--format" "${toString selfConfig.format}"] - else [] - ) - ++ ( - if selfConfig.color != "" - then ["--color" "${toString selfConfig.color}"] - else [] - ) - # 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 buildConfig.pdfDirectory ["." ""]) - then ["--outdir" "${buildConfig.pdfDirectory}"] - else [] - ) - ); - custom = buildConfig: buildConfig.custom.args; - }; + # # --- Arg Collation Functions -- + # collateArgs.lsp.texlab.build = { + # tectonic = buildConfig: let + # selfConfig = buildConfig.tectonic; + # in ( + # # Base args + # [ + # "-X" + # "compile" + # "%f" + # ] + # # Flags + # ++ ( + # if selfConfig.keepIntermediates + # then ["--keep-intermediates"] + # else [] + # ) + # ++ ( + # if selfConfig.keepLogs + # then ["--keep-logs"] + # else [] + # ) + # ++ ( + # if selfConfig.onlyCached + # then ["--only-cached"] + # else [] + # ) + # ++ ( + # if selfConfig.synctex + # then ["--synctex"] + # else [] + # ) + # ++ ( + # if selfConfig.untrustedInput + # then ["--untrusted"] + # else [] + # ) + # # Options + # ++ ( + # if selfConfig.reruns > 0 + # then ["--reruns" "${toString selfConfig.reruns}"] + # else [] + # ) + # ++ ( + # if selfConfig.bundle != "" + # then ["--bundle" "${toString selfConfig.bundle}"] + # else [] + # ) + # ++ ( + # if selfConfig.webBundle != "" + # then ["--web-bundle" "${toString selfConfig.webBundle}"] + # else [] + # ) + # ++ ( + # if selfConfig.outfmt != "" + # then ["--outfmt" "${toString selfConfig.outfmt}"] + # else [] + # ) + # ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + # ++ ( + # if selfConfig.format != "" + # then ["--format" "${toString selfConfig.format}"] + # else [] + # ) + # ++ ( + # if selfConfig.color != "" + # then ["--color" "${toString selfConfig.color}"] + # else [] + # ) + # # 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 buildConfig.pdfDirectory ["." ""]) + # then ["--outdir" "${buildConfig.pdfDirectory}"] + # else [] + # ) + # ); + # custom = buildConfig: buildConfig.custom.args; + # }; in { imports = [ ./treesitter.nix + ./lsp ]; options.vim.languages.tex = { @@ -168,286 +169,286 @@ in { # more sense to group one into its own group of options. # # Each lsp group must have an enable option of its own. - lsp = { - texlab = { - enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; - - package = mkOption { - type = package; - default = pkgs.texlab; - description = "texlab package"; - }; - - build = { - tectonic = { - enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; - - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; - - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - - # -- Flags -- - keepIntermediates = mkEnableDefaultOption false '' - Keep the intermediate files generated during processing. - - If texlab is reporting build errors when there shouldn't be, disable this option. - ''; - keepLogs = mkEnableDefaultOption true '' - Keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation warnings. - ''; - onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = "Rerun the TeX engine exactly this many times after the first"; - }; - - bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - }; - - webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; - }; - - outfmt = mkOption { - type = enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = "Tell the engine that no file at exists, if it tries to read it."; - }; - - format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; - }; - - color = mkOption { - type = enum [ - "always" - "auto" - "never" - "" - ]; - default = ""; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. - ''; - }; - }; - - custom = { - enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "build/compiler package"; - }; - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - args = mkOption { - type = listOf str; - default = [ - "-X" - "compile" - "%f" - "--synctex" - "--keep-logs" - "--keep-intermediates" - ]; - description = '' - Defines additional arguments that are passed to the configured LaTeX build tool. - Note that flags and their arguments need to be separate elements in this array. - To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - The placeholder `%f` will be replaced by the server. - - Placeholders: - - `%f`: The path of the TeX file to compile. - ''; - }; - }; - - forwardSearchAfter = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to execute a forward search after a build."; - }; - onSave = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to compile the project after saving a file."; - }; - useFileList = mkOption { - type = bool; - default = false; - description = '' - When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. - - Note that enabling this property might have an impact on performance. - ''; - }; - auxDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the .aux files. - Note that you need to set the aux directory in latex.build.args too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - logDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the build log files. - Note that you need to change the output directory in your build arguments too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - pdfDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the output files. - Note that you need to set the output directory in latex.build.args too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - filename = mkOption { - type = str; - default = ""; - 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. - ''; - }; - }; - - forwardSearch = { - enable = mkOption { - type = bool; - default = false; - example = true; - description = '' - Whether to enable forward search. - - Enable this option if you want to have the compiled document appear in your chosen PDF viewer. - - For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - Note this is not all the options, but can act as a guide to help you allong with custom configs. - ''; - }; - package = mkOption { - type = package; - default = pkgs.okular; - description = '' - The package to use as your PDF viewer. - This viewer needs to support Synctex. - ''; - }; - executable = mkOption { - type = str; - default = "okular"; - description = '' - Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. - ''; - }; - args = mkOption { - type = listOf str; - default = [ - "--unique" - "file:%p#src:%l%f" - ]; - description = '' - Defines additional arguments that are passed to the configured previewer to perform the forward search. - The placeholders %f, %p, %l will be replaced by the server. - - Placeholders: - - %f: The path of the current TeX file. - - %p: The path of the current PDF file. - - %l: The current line number. - ''; - }; - }; - - extraLuaSettings = mkOption { - type = str; - default = ""; - example = '' - formatterLineLength = 80, - ''; - description = '' - For any options that do not have options provided through nvf this can be used to add them. - Options already declared in nvf config will NOT be overridden. - - Options will be placed in: - ``` - lspconfig.texlab.setup { - settings = { - texlab = { - ... - - ... - - } - } - } - ``` - ''; - }; - }; - - # Add other LSPs here - }; + # lsp = { + # texlab = { + # enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; + # + # package = mkOption { + # type = package; + # default = pkgs.texlab; + # description = "texlab package"; + # }; + # + # build = { + # tectonic = { + # enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; + # + # package = mkOption { + # type = package; + # default = pkgs.tectonic; + # description = "tectonic package"; + # }; + # + # executable = mkOption { + # type = str; + # default = "tectonic"; + # description = "The executable name from the build package that will be used to build/compile the tex."; + # }; + # + # # -- Flags -- + # keepIntermediates = mkEnableDefaultOption false '' + # Keep the intermediate files generated during processing. + # + # If texlab is reporting build errors when there shouldn't be, disable this option. + # ''; + # keepLogs = mkEnableDefaultOption true '' + # Keep the log files generated during processing. + # + # Without the keepLogs flag, texlab won't be able to report compilation warnings. + # ''; + # onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + # synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + # untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + # + # # -- Options -- + # reruns = mkOption { + # type = ints.unsigned; + # default = 0; + # example = 2; + # description = "Rerun the TeX engine exactly this many times after the first"; + # }; + # + # bundle = mkOption { + # type = str; + # default = ""; + # description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + # }; + # + # webBundle = mkOption { + # type = str; + # default = ""; + # description = "Use this URL to find resource files instead of the default"; + # }; + # + # outfmt = mkOption { + # type = enum [ + # "pdf" + # "html" + # "xdv" + # "aux" + # "fmt" + # "" + # ]; + # default = ""; + # description = "The kind of output to generate"; + # }; + # + # hidePaths = mkOption { + # type = listOf str; + # default = []; + # example = [ + # "./secrets.tex" + # "./passwords.tex" + # ]; + # description = "Tell the engine that no file at exists, if it tries to read it."; + # }; + # + # format = mkOption { + # type = str; + # default = ""; + # description = "The name of the \"format\" file used to initialize the TeX engine"; + # }; + # + # color = mkOption { + # type = enum [ + # "always" + # "auto" + # "never" + # "" + # ]; + # default = ""; + # example = "always"; + # description = "Enable/disable colorful log output"; + # }; + # + # extraOptions = { + # type = listOf str; + # default = []; + # description = '' + # Add extra command line options to include in the tectonic build command. + # Extra options added here will not overwrite the options set in as nvf options. + # ''; + # }; + # }; + # + # custom = { + # enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; + # package = mkOption { + # type = package; + # default = pkgs.tectonic; + # description = "build/compiler package"; + # }; + # executable = mkOption { + # type = str; + # default = "tectonic"; + # description = "The executable name from the build package that will be used to build/compile the tex."; + # }; + # args = mkOption { + # type = listOf str; + # default = [ + # "-X" + # "compile" + # "%f" + # "--synctex" + # "--keep-logs" + # "--keep-intermediates" + # ]; + # description = '' + # Defines additional arguments that are passed to the configured LaTeX build tool. + # Note that flags and their arguments need to be separate elements in this array. + # To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + # The placeholder `%f` will be replaced by the server. + # + # Placeholders: + # - `%f`: The path of the TeX file to compile. + # ''; + # }; + # }; + # + # forwardSearchAfter = mkOption { + # type = bool; + # default = false; + # description = "Set this property to true if you want to execute a forward search after a build."; + # }; + # onSave = mkOption { + # type = bool; + # default = false; + # description = "Set this property to true if you want to compile the project after saving a file."; + # }; + # useFileList = mkOption { + # type = bool; + # default = false; + # description = '' + # When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + # + # Note that enabling this property might have an impact on performance. + # ''; + # }; + # auxDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the .aux files. + # Note that you need to set the aux directory in latex.build.args too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # logDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the build log files. + # Note that you need to change the output directory in your build arguments too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # pdfDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the output files. + # Note that you need to set the output directory in latex.build.args too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # filename = mkOption { + # type = str; + # default = ""; + # 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. + # ''; + # }; + # }; + # + # forwardSearch = { + # enable = mkOption { + # type = bool; + # default = false; + # example = true; + # description = '' + # Whether to enable forward search. + # + # Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + # + # For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + # Note this is not all the options, but can act as a guide to help you allong with custom configs. + # ''; + # }; + # package = mkOption { + # type = package; + # default = pkgs.okular; + # description = '' + # The package to use as your PDF viewer. + # This viewer needs to support Synctex. + # ''; + # }; + # executable = mkOption { + # type = str; + # default = "okular"; + # description = '' + # Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + # ''; + # }; + # args = mkOption { + # type = listOf str; + # default = [ + # "--unique" + # "file:%p#src:%l%f" + # ]; + # description = '' + # Defines additional arguments that are passed to the configured previewer to perform the forward search. + # The placeholders %f, %p, %l will be replaced by the server. + # + # Placeholders: + # - %f: The path of the current TeX file. + # - %p: The path of the current PDF file. + # - %l: The current line number. + # ''; + # }; + # }; + # + # extraLuaSettings = mkOption { + # type = str; + # default = ""; + # example = '' + # formatterLineLength = 80, + # ''; + # description = '' + # For any options that do not have options provided through nvf this can be used to add them. + # Options already declared in nvf config will NOT be overridden. + # + # Options will be placed in: + # ``` + # lspconfig.texlab.setup { + # settings = { + # texlab = { + # ... + # + # ... + # + # } + # } + # } + # ``` + # ''; + # }; + # }; + # + # # Add other LSPs here + # }; extraOpts = { texFlavor = { @@ -501,120 +502,120 @@ in { # }) # LSP - (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( - { - vim.lsp.lspconfig.enable = true; - } # Enable lspconfig when any of the lsps are enabled - // (mkMerge [ - # ----- Texlab ----- - ( - let - tl = cfg.lsp.texlab; - build = tl.build; - - listToLua = list: nullOnEmpty: - if length list == 0 - then - if nullOnEmpty - then "null" - else "{ }" - else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; - - stringToLua = string: nullOnEmpty: - if string == "" - then - if nullOnEmpty - then "null" - else "" - else ''"${string}"''; - - boolToLua = boolean: - if boolean - then "true" - else "false"; - - # -- Build -- - buildConfig = let - # This function will sort through the builder options of ...texlab.build and count how many - # builders have been enabled and get the attrs of the last enabled builder. - getBuilder = { - enabledBuildersCount ? 0, - enabledBuilderName ? "", - index ? 0, - builderNamesList ? ( - filter ( - x: let - y = tl.build.${x}; - in (isAttrs y && hasAttr "enable" y) - ) (attrNames tl.build) - ), - }: let - currentBuilderName = elemAt builderNamesList index; - currentBuilder = tl.build.${currentBuilderName}; - nextIndex = index + 1; - currentState = { - enabledBuildersCount = - if currentBuilder.enable - then enabledBuildersCount + 1 - else enabledBuildersCount; - enabledBuilderName = - if currentBuilder.enable - then currentBuilderName - else enabledBuilderName; - }; - in - if length builderNamesList > nextIndex - then - getBuilder ({ - inherit builderNamesList; - index = nextIndex; - } - // currentState) - else currentState; - - getBuilderResults = getBuilder {}; - builder = tl.build.${getBuilderResults.enabledBuilderName}; - builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; - in - if getBuilderResults.enabledBuildersCount == 0 - then "" - else if getBuilderResults.enabledBuildersCount > 1 - then throw "Texlab does not support having more than 1 builders enabled!" - else '' - build = { - executable = "${builder.package}/bin/${builder.executable}", - args = ${listToLua builderArgs false}, - forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, - onSave = ${boolToLua build.onSave}, - useFileList = ${boolToLua build.useFileList}, - auxDirectory = ${stringToLua build.auxDirectory true}, - logDirectory = ${stringToLua build.logDirectory true}, - pdfDirectory = ${stringToLua build.pdfDirectory true}, - filename = ${stringToLua build.filename true}, - }, - ''; - in (mkIf tl.enable { - vim.lsp.lspconfig.sources.texlab = '' - lspconfig.texlab.setup { - cmd = { "${tl.package}/bin/texlab" }, - settings = { - texlab = { - ${buildConfig} - forwardSearch = { - executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", - args = ${listToLua tl.forwardSearch.args true} - }, - ${tl.extraLuaSettings} - } - } - } - ''; - }) - ) - - # Add other LSPs here - ]) - )) + # (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( + # { + # vim.lsp.lspconfig.enable = true; + # } # Enable lspconfig when any of the lsps are enabled + # // (mkMerge [ + # # ----- Texlab ----- + # ( + # let + # tl = cfg.lsp.texlab; + # build = tl.build; + # + # listToLua = list: nullOnEmpty: + # if length list == 0 + # then + # if nullOnEmpty + # then "null" + # else "{ }" + # else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + # + # stringToLua = string: nullOnEmpty: + # if string == "" + # then + # if nullOnEmpty + # then "null" + # else "" + # else ''"${string}"''; + # + # boolToLua = boolean: + # if boolean + # then "true" + # else "false"; + # + # # -- Build -- + # buildConfig = let + # # This function will sort through the builder options of ...texlab.build and count how many + # # builders have been enabled and get the attrs of the last enabled builder. + # getBuilder = { + # enabledBuildersCount ? 0, + # enabledBuilderName ? "", + # index ? 0, + # builderNamesList ? ( + # filter ( + # x: let + # y = tl.build.${x}; + # in (isAttrs y && hasAttr "enable" y) + # ) (attrNames tl.build) + # ), + # }: let + # currentBuilderName = elemAt builderNamesList index; + # currentBuilder = tl.build.${currentBuilderName}; + # nextIndex = index + 1; + # currentState = { + # enabledBuildersCount = + # if currentBuilder.enable + # then enabledBuildersCount + 1 + # else enabledBuildersCount; + # enabledBuilderName = + # if currentBuilder.enable + # then currentBuilderName + # else enabledBuilderName; + # }; + # in + # if length builderNamesList > nextIndex + # then + # getBuilder ({ + # inherit builderNamesList; + # index = nextIndex; + # } + # // currentState) + # else currentState; + # + # getBuilderResults = getBuilder {}; + # builder = tl.build.${getBuilderResults.enabledBuilderName}; + # builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; + # in + # if getBuilderResults.enabledBuildersCount == 0 + # then "" + # else if getBuilderResults.enabledBuildersCount > 1 + # then throw "Texlab does not support having more than 1 builders enabled!" + # else '' + # build = { + # executable = "${builder.package}/bin/${builder.executable}", + # args = ${listToLua builderArgs false}, + # forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, + # onSave = ${boolToLua build.onSave}, + # useFileList = ${boolToLua build.useFileList}, + # auxDirectory = ${stringToLua build.auxDirectory true}, + # logDirectory = ${stringToLua build.logDirectory true}, + # pdfDirectory = ${stringToLua build.pdfDirectory true}, + # filename = ${stringToLua build.filename true}, + # }, + # ''; + # in (mkIf tl.enable { + # vim.lsp.lspconfig.sources.texlab = '' + # lspconfig.texlab.setup { + # cmd = { "${tl.package}/bin/texlab" }, + # settings = { + # texlab = { + # ${buildConfig} + # forwardSearch = { + # executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", + # args = ${listToLua tl.forwardSearch.args true} + # }, + # ${tl.extraLuaSettings} + # } + # } + # } + # ''; + # }) + # ) + # + # # Add other LSPs here + # ]) + # )) # Extra Lua config options (mkIf cfg.extraOpts.texFlavor.enable { diff --git a/modules/plugins/languages/tex/lsp/default.nix b/modules/plugins/languages/tex/lsp/default.nix new file mode 100644 index 00000000..3c48d515 --- /dev/null +++ b/modules/plugins/languages/tex/lsp/default.nix @@ -0,0 +1,528 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge; + inherit + (lib.types) + bool + either + enum + ints + listOf + oneOf + package + str + ; + inherit (lib.nvim.types) mkGrammarOption; + inherit + (builtins) + any + attrNames + attrValues + concatLists + concatStringsSep + elem + elemAt + filter + hasAttr + isAttrs + length + map + throw + toString + ; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); + mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; + + # --- Arg Collation Functions -- + collateArgs.lsp.texlab.build = { + tectonic = buildConfig: let + selfConfig = buildConfig.tectonic; + in ( + # Base args + [ + "-X" + "compile" + "%f" + ] + # Flags + ++ ( + if selfConfig.keepIntermediates + then ["--keep-intermediates"] + else [] + ) + ++ ( + if selfConfig.keepLogs + then ["--keep-logs"] + else [] + ) + ++ ( + if selfConfig.onlyCached + then ["--only-cached"] + else [] + ) + ++ ( + if selfConfig.synctex + then ["--synctex"] + else [] + ) + ++ ( + if selfConfig.untrustedInput + then ["--untrusted"] + else [] + ) + # Options + ++ ( + if selfConfig.reruns > 0 + then ["--reruns" "${toString selfConfig.reruns}"] + else [] + ) + ++ ( + if selfConfig.bundle != "" + then ["--bundle" "${toString selfConfig.bundle}"] + else [] + ) + ++ ( + if selfConfig.webBundle != "" + then ["--web-bundle" "${toString selfConfig.webBundle}"] + else [] + ) + ++ ( + if selfConfig.outfmt != "" + then ["--outfmt" "${toString selfConfig.outfmt}"] + else [] + ) + ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + ++ ( + if selfConfig.format != "" + then ["--format" "${toString selfConfig.format}"] + else [] + ) + ++ ( + if selfConfig.color != "" + then ["--color" "${toString selfConfig.color}"] + else [] + ) + # 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 buildConfig.pdfDirectory ["." ""]) + then ["--outdir" "${buildConfig.pdfDirectory}"] + else [] + ) + ); + custom = buildConfig: buildConfig.custom.args; + }; +in { + options.vim.languages.tex.lsp = { + texlab = { + enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; + + package = mkOption { + type = package; + default = pkgs.texlab; + description = "texlab package"; + }; + + build = { + tectonic = { + enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; + + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; + }; + + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # -- Flags -- + keepIntermediates = mkEnableDefaultOption false '' + Keep the intermediate files generated during processing. + + If texlab is reporting build errors when there shouldn't be, disable this option. + ''; + keepLogs = mkEnableDefaultOption true '' + Keep the log files generated during processing. + + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = "Rerun the TeX engine exactly this many times after the first"; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; + }; + + custom = { + enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "build/compiler package"; + }; + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + args = mkOption { + type = listOf str; + default = [ + "-X" + "compile" + "%f" + "--synctex" + "--keep-logs" + "--keep-intermediates" + ]; + description = '' + Defines additional arguments that are passed to the configured LaTeX build tool. + Note that flags and their arguments need to be separate elements in this array. + To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + The placeholder `%f` will be replaced by the server. + + Placeholders: + - `%f`: The path of the TeX file to compile. + ''; + }; + }; + + forwardSearchAfter = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to execute a forward search after a build."; + }; + onSave = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to compile the project after saving a file."; + }; + useFileList = mkOption { + type = bool; + default = false; + description = '' + When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + + Note that enabling this property might have an impact on performance. + ''; + }; + auxDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the .aux files. + Note that you need to set the aux directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + logDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the build log files. + Note that you need to change the output directory in your build arguments too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + pdfDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the output files. + Note that you need to set the output directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + filename = mkOption { + type = str; + default = ""; + 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. + ''; + }; + }; + + forwardSearch = { + enable = mkOption { + type = bool; + default = false; + example = true; + description = '' + Whether to enable forward search. + + Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + + For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + Note this is not all the options, but can act as a guide to help you allong with custom configs. + ''; + }; + package = mkOption { + type = package; + default = pkgs.okular; + description = '' + The package to use as your PDF viewer. + This viewer needs to support Synctex. + ''; + }; + executable = mkOption { + type = str; + default = "okular"; + description = '' + Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + ''; + }; + args = mkOption { + type = listOf str; + default = [ + "--unique" + "file:%p#src:%l%f" + ]; + description = '' + Defines additional arguments that are passed to the configured previewer to perform the forward search. + The placeholders %f, %p, %l will be replaced by the server. + + Placeholders: + - %f: The path of the current TeX file. + - %p: The path of the current PDF file. + - %l: The current line number. + ''; + }; + }; + + extraLuaSettings = mkOption { + type = str; + default = ""; + example = '' + formatterLineLength = 80, + ''; + description = '' + For any options that do not have options provided through nvf this can be used to add them. + Options already declared in nvf config will NOT be overridden. + + Options will be placed in: + ``` + lspconfig.texlab.setup { + settings = { + texlab = { + ... + + ... + + } + } + } + ``` + ''; + }; + }; + + # Add other LSPs here + }; + + # config = mkIf cfg.enable (mkMerge [ + # (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( + config = mkIf (cfg.enable && (any (x: x.enable) (attrValues cfg.lsp))) ( + { + vim.lsp.lspconfig.enable = true; + } # Enable lspconfig when any of the lsps are enabled + // (mkMerge [ + # ----- Texlab ----- + ( + let + tl = cfg.lsp.texlab; + build = tl.build; + + listToLua = list: nullOnEmpty: + if length list == 0 + then + if nullOnEmpty + then "null" + else "{ }" + else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + + stringToLua = string: nullOnEmpty: + if string == "" + then + if nullOnEmpty + then "null" + else "" + else ''"${string}"''; + + boolToLua = boolean: + if boolean + then "true" + else "false"; + + # -- Build -- + buildConfig = let + # This function will sort through the builder options of ...texlab.build and count how many + # builders have been enabled and get the attrs of the last enabled builder. + getBuilder = { + enabledBuildersCount ? 0, + enabledBuilderName ? "", + index ? 0, + builderNamesList ? ( + filter ( + x: let + y = tl.build.${x}; + in (isAttrs y && hasAttr "enable" y) + ) (attrNames tl.build) + ), + }: let + currentBuilderName = elemAt builderNamesList index; + currentBuilder = tl.build.${currentBuilderName}; + nextIndex = index + 1; + currentState = { + enabledBuildersCount = + if currentBuilder.enable + then enabledBuildersCount + 1 + else enabledBuildersCount; + enabledBuilderName = + if currentBuilder.enable + then currentBuilderName + else enabledBuilderName; + }; + in + if length builderNamesList > nextIndex + then + getBuilder ({ + inherit builderNamesList; + index = nextIndex; + } + // currentState) + else currentState; + + getBuilderResults = getBuilder {}; + builder = tl.build.${getBuilderResults.enabledBuilderName}; + builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; + in + if getBuilderResults.enabledBuildersCount == 0 + then "" + else if getBuilderResults.enabledBuildersCount > 1 + then throw "Texlab does not support having more than 1 builders enabled!" + else '' + build = { + executable = "${builder.package}/bin/${builder.executable}", + args = ${listToLua builderArgs false}, + forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, + onSave = ${boolToLua build.onSave}, + useFileList = ${boolToLua build.useFileList}, + auxDirectory = ${stringToLua build.auxDirectory true}, + logDirectory = ${stringToLua build.logDirectory true}, + pdfDirectory = ${stringToLua build.pdfDirectory true}, + filename = ${stringToLua build.filename true}, + }, + ''; + in (mkIf tl.enable { + vim.lsp.lspconfig.sources.texlab = '' + lspconfig.texlab.setup { + cmd = { "${tl.package}/bin/texlab" }, + settings = { + texlab = { + ${buildConfig} + forwardSearch = { + executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", + args = ${listToLua tl.forwardSearch.args true} + }, + ${tl.extraLuaSettings} + } + } + } + ''; + }) + ) + + # Add other LSPs here + ]) + ); +} From aa191b683e25d98fec2b7311d4ee0fe4d9df0e0f Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 16:54:21 -0700 Subject: [PATCH 15/65] Migrated texlab into its own module --- modules/plugins/languages/tex/lsp/default.nix | 951 +++++++++--------- modules/plugins/languages/tex/lsp/texlab.nix | 512 ++++++++++ 2 files changed, 989 insertions(+), 474 deletions(-) create mode 100644 modules/plugins/languages/tex/lsp/texlab.nix diff --git a/modules/plugins/languages/tex/lsp/default.nix b/modules/plugins/languages/tex/lsp/default.nix index 3c48d515..ffffe5cf 100644 --- a/modules/plugins/languages/tex/lsp/default.nix +++ b/modules/plugins/languages/tex/lsp/default.nix @@ -39,375 +39,378 @@ cfg = config.vim.languages.tex; # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); - mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; + # mkEnableDefaultOption = default: description: (mkOption { + # type = bool; + # default = default; + # example = !default; + # description = description; + # }); + # mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; - # --- Arg Collation Functions -- - collateArgs.lsp.texlab.build = { - tectonic = buildConfig: let - selfConfig = buildConfig.tectonic; - in ( - # Base args - [ - "-X" - "compile" - "%f" - ] - # Flags - ++ ( - if selfConfig.keepIntermediates - then ["--keep-intermediates"] - else [] - ) - ++ ( - if selfConfig.keepLogs - then ["--keep-logs"] - else [] - ) - ++ ( - if selfConfig.onlyCached - then ["--only-cached"] - else [] - ) - ++ ( - if selfConfig.synctex - then ["--synctex"] - else [] - ) - ++ ( - if selfConfig.untrustedInput - then ["--untrusted"] - else [] - ) - # Options - ++ ( - if selfConfig.reruns > 0 - then ["--reruns" "${toString selfConfig.reruns}"] - else [] - ) - ++ ( - if selfConfig.bundle != "" - then ["--bundle" "${toString selfConfig.bundle}"] - else [] - ) - ++ ( - if selfConfig.webBundle != "" - then ["--web-bundle" "${toString selfConfig.webBundle}"] - else [] - ) - ++ ( - if selfConfig.outfmt != "" - then ["--outfmt" "${toString selfConfig.outfmt}"] - else [] - ) - ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - ++ ( - if selfConfig.format != "" - then ["--format" "${toString selfConfig.format}"] - else [] - ) - ++ ( - if selfConfig.color != "" - then ["--color" "${toString selfConfig.color}"] - else [] - ) - # 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 buildConfig.pdfDirectory ["." ""]) - then ["--outdir" "${buildConfig.pdfDirectory}"] - else [] - ) - ); - custom = buildConfig: buildConfig.custom.args; - }; + # # --- Arg Collation Functions -- + # collateArgs.lsp.texlab.build = { + # tectonic = buildConfig: let + # selfConfig = buildConfig.tectonic; + # in ( + # # Base args + # [ + # "-X" + # "compile" + # "%f" + # ] + # # Flags + # ++ ( + # if selfConfig.keepIntermediates + # then ["--keep-intermediates"] + # else [] + # ) + # ++ ( + # if selfConfig.keepLogs + # then ["--keep-logs"] + # else [] + # ) + # ++ ( + # if selfConfig.onlyCached + # then ["--only-cached"] + # else [] + # ) + # ++ ( + # if selfConfig.synctex + # then ["--synctex"] + # else [] + # ) + # ++ ( + # if selfConfig.untrustedInput + # then ["--untrusted"] + # else [] + # ) + # # Options + # ++ ( + # if selfConfig.reruns > 0 + # then ["--reruns" "${toString selfConfig.reruns}"] + # else [] + # ) + # ++ ( + # if selfConfig.bundle != "" + # then ["--bundle" "${toString selfConfig.bundle}"] + # else [] + # ) + # ++ ( + # if selfConfig.webBundle != "" + # then ["--web-bundle" "${toString selfConfig.webBundle}"] + # else [] + # ) + # ++ ( + # if selfConfig.outfmt != "" + # then ["--outfmt" "${toString selfConfig.outfmt}"] + # else [] + # ) + # ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + # ++ ( + # if selfConfig.format != "" + # then ["--format" "${toString selfConfig.format}"] + # else [] + # ) + # ++ ( + # if selfConfig.color != "" + # then ["--color" "${toString selfConfig.color}"] + # else [] + # ) + # # 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 buildConfig.pdfDirectory ["." ""]) + # then ["--outdir" "${buildConfig.pdfDirectory}"] + # else [] + # ) + # ); + # custom = buildConfig: buildConfig.custom.args; + # }; in { - options.vim.languages.tex.lsp = { - texlab = { - enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; - - package = mkOption { - type = package; - default = pkgs.texlab; - description = "texlab package"; - }; - - build = { - tectonic = { - enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; - - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; - - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - - # -- Flags -- - keepIntermediates = mkEnableDefaultOption false '' - Keep the intermediate files generated during processing. - - If texlab is reporting build errors when there shouldn't be, disable this option. - ''; - keepLogs = mkEnableDefaultOption true '' - Keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation warnings. - ''; - onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = "Rerun the TeX engine exactly this many times after the first"; - }; - - bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - }; - - webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; - }; - - outfmt = mkOption { - type = enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = "Tell the engine that no file at exists, if it tries to read it."; - }; - - format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; - }; - - color = mkOption { - type = enum [ - "always" - "auto" - "never" - "" - ]; - default = ""; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. - ''; - }; - }; - - custom = { - enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "build/compiler package"; - }; - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - args = mkOption { - type = listOf str; - default = [ - "-X" - "compile" - "%f" - "--synctex" - "--keep-logs" - "--keep-intermediates" - ]; - description = '' - Defines additional arguments that are passed to the configured LaTeX build tool. - Note that flags and their arguments need to be separate elements in this array. - To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - The placeholder `%f` will be replaced by the server. - - Placeholders: - - `%f`: The path of the TeX file to compile. - ''; - }; - }; - - forwardSearchAfter = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to execute a forward search after a build."; - }; - onSave = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to compile the project after saving a file."; - }; - useFileList = mkOption { - type = bool; - default = false; - description = '' - When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. - - Note that enabling this property might have an impact on performance. - ''; - }; - auxDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the .aux files. - Note that you need to set the aux directory in latex.build.args too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - logDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the build log files. - Note that you need to change the output directory in your build arguments too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - pdfDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the output files. - Note that you need to set the output directory in latex.build.args too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - filename = mkOption { - type = str; - default = ""; - 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. - ''; - }; - }; - - forwardSearch = { - enable = mkOption { - type = bool; - default = false; - example = true; - description = '' - Whether to enable forward search. - - Enable this option if you want to have the compiled document appear in your chosen PDF viewer. - - For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - Note this is not all the options, but can act as a guide to help you allong with custom configs. - ''; - }; - package = mkOption { - type = package; - default = pkgs.okular; - description = '' - The package to use as your PDF viewer. - This viewer needs to support Synctex. - ''; - }; - executable = mkOption { - type = str; - default = "okular"; - description = '' - Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. - ''; - }; - args = mkOption { - type = listOf str; - default = [ - "--unique" - "file:%p#src:%l%f" - ]; - description = '' - Defines additional arguments that are passed to the configured previewer to perform the forward search. - The placeholders %f, %p, %l will be replaced by the server. - - Placeholders: - - %f: The path of the current TeX file. - - %p: The path of the current PDF file. - - %l: The current line number. - ''; - }; - }; - - extraLuaSettings = mkOption { - type = str; - default = ""; - example = '' - formatterLineLength = 80, - ''; - description = '' - For any options that do not have options provided through nvf this can be used to add them. - Options already declared in nvf config will NOT be overridden. - - Options will be placed in: - ``` - lspconfig.texlab.setup { - settings = { - texlab = { - ... - - ... - - } - } - } - ``` - ''; - }; - }; + imports = [ + ./texlab.nix + ]; + # options.vim.languages.tex.lsp = { + # texlab = { + # enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; + # + # package = mkOption { + # type = package; + # default = pkgs.texlab; + # description = "texlab package"; + # }; + # + # build = { + # tectonic = { + # enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; + # + # package = mkOption { + # type = package; + # default = pkgs.tectonic; + # description = "tectonic package"; + # }; + # + # executable = mkOption { + # type = str; + # default = "tectonic"; + # description = "The executable name from the build package that will be used to build/compile the tex."; + # }; + # + # # -- Flags -- + # keepIntermediates = mkEnableDefaultOption false '' + # Keep the intermediate files generated during processing. + # + # If texlab is reporting build errors when there shouldn't be, disable this option. + # ''; + # keepLogs = mkEnableDefaultOption true '' + # Keep the log files generated during processing. + # + # Without the keepLogs flag, texlab won't be able to report compilation warnings. + # ''; + # onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + # synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + # untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + # + # # -- Options -- + # reruns = mkOption { + # type = ints.unsigned; + # default = 0; + # example = 2; + # description = "Rerun the TeX engine exactly this many times after the first"; + # }; + # + # bundle = mkOption { + # type = str; + # default = ""; + # description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + # }; + # + # webBundle = mkOption { + # type = str; + # default = ""; + # description = "Use this URL to find resource files instead of the default"; + # }; + # + # outfmt = mkOption { + # type = enum [ + # "pdf" + # "html" + # "xdv" + # "aux" + # "fmt" + # "" + # ]; + # default = ""; + # description = "The kind of output to generate"; + # }; + # + # hidePaths = mkOption { + # type = listOf str; + # default = []; + # example = [ + # "./secrets.tex" + # "./passwords.tex" + # ]; + # description = "Tell the engine that no file at exists, if it tries to read it."; + # }; + # + # format = mkOption { + # type = str; + # default = ""; + # description = "The name of the \"format\" file used to initialize the TeX engine"; + # }; + # + # color = mkOption { + # type = enum [ + # "always" + # "auto" + # "never" + # "" + # ]; + # default = ""; + # example = "always"; + # description = "Enable/disable colorful log output"; + # }; + # + # extraOptions = { + # type = listOf str; + # default = []; + # description = '' + # Add extra command line options to include in the tectonic build command. + # Extra options added here will not overwrite the options set in as nvf options. + # ''; + # }; + # }; + # + # custom = { + # enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; + # package = mkOption { + # type = package; + # default = pkgs.tectonic; + # description = "build/compiler package"; + # }; + # executable = mkOption { + # type = str; + # default = "tectonic"; + # description = "The executable name from the build package that will be used to build/compile the tex."; + # }; + # args = mkOption { + # type = listOf str; + # default = [ + # "-X" + # "compile" + # "%f" + # "--synctex" + # "--keep-logs" + # "--keep-intermediates" + # ]; + # description = '' + # Defines additional arguments that are passed to the configured LaTeX build tool. + # Note that flags and their arguments need to be separate elements in this array. + # To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + # The placeholder `%f` will be replaced by the server. + # + # Placeholders: + # - `%f`: The path of the TeX file to compile. + # ''; + # }; + # }; + # + # forwardSearchAfter = mkOption { + # type = bool; + # default = false; + # description = "Set this property to true if you want to execute a forward search after a build."; + # }; + # onSave = mkOption { + # type = bool; + # default = false; + # description = "Set this property to true if you want to compile the project after saving a file."; + # }; + # useFileList = mkOption { + # type = bool; + # default = false; + # description = '' + # When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + # + # Note that enabling this property might have an impact on performance. + # ''; + # }; + # auxDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the .aux files. + # Note that you need to set the aux directory in latex.build.args too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # logDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the build log files. + # Note that you need to change the output directory in your build arguments too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # pdfDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the output files. + # Note that you need to set the output directory in latex.build.args too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # filename = mkOption { + # type = str; + # default = ""; + # 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. + # ''; + # }; + # }; + # + # forwardSearch = { + # enable = mkOption { + # type = bool; + # default = false; + # example = true; + # description = '' + # Whether to enable forward search. + # + # Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + # + # For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + # Note this is not all the options, but can act as a guide to help you allong with custom configs. + # ''; + # }; + # package = mkOption { + # type = package; + # default = pkgs.okular; + # description = '' + # The package to use as your PDF viewer. + # This viewer needs to support Synctex. + # ''; + # }; + # executable = mkOption { + # type = str; + # default = "okular"; + # description = '' + # Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + # ''; + # }; + # args = mkOption { + # type = listOf str; + # default = [ + # "--unique" + # "file:%p#src:%l%f" + # ]; + # description = '' + # Defines additional arguments that are passed to the configured previewer to perform the forward search. + # The placeholders %f, %p, %l will be replaced by the server. + # + # Placeholders: + # - %f: The path of the current TeX file. + # - %p: The path of the current PDF file. + # - %l: The current line number. + # ''; + # }; + # }; + # + # extraLuaSettings = mkOption { + # type = str; + # default = ""; + # example = '' + # formatterLineLength = 80, + # ''; + # description = '' + # For any options that do not have options provided through nvf this can be used to add them. + # Options already declared in nvf config will NOT be overridden. + # + # Options will be placed in: + # ``` + # lspconfig.texlab.setup { + # settings = { + # texlab = { + # ... + # + # ... + # + # } + # } + # } + # ``` + # ''; + # }; + # }; # Add other LSPs here - }; + # }; # config = mkIf cfg.enable (mkMerge [ # (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( @@ -415,114 +418,114 @@ in { { vim.lsp.lspconfig.enable = true; } # Enable lspconfig when any of the lsps are enabled - // (mkMerge [ - # ----- Texlab ----- - ( - let - tl = cfg.lsp.texlab; - build = tl.build; - - listToLua = list: nullOnEmpty: - if length list == 0 - then - if nullOnEmpty - then "null" - else "{ }" - else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; - - stringToLua = string: nullOnEmpty: - if string == "" - then - if nullOnEmpty - then "null" - else "" - else ''"${string}"''; - - boolToLua = boolean: - if boolean - then "true" - else "false"; - - # -- Build -- - buildConfig = let - # This function will sort through the builder options of ...texlab.build and count how many - # builders have been enabled and get the attrs of the last enabled builder. - getBuilder = { - enabledBuildersCount ? 0, - enabledBuilderName ? "", - index ? 0, - builderNamesList ? ( - filter ( - x: let - y = tl.build.${x}; - in (isAttrs y && hasAttr "enable" y) - ) (attrNames tl.build) - ), - }: let - currentBuilderName = elemAt builderNamesList index; - currentBuilder = tl.build.${currentBuilderName}; - nextIndex = index + 1; - currentState = { - enabledBuildersCount = - if currentBuilder.enable - then enabledBuildersCount + 1 - else enabledBuildersCount; - enabledBuilderName = - if currentBuilder.enable - then currentBuilderName - else enabledBuilderName; - }; - in - if length builderNamesList > nextIndex - then - getBuilder ({ - inherit builderNamesList; - index = nextIndex; - } - // currentState) - else currentState; - - getBuilderResults = getBuilder {}; - builder = tl.build.${getBuilderResults.enabledBuilderName}; - builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; - in - if getBuilderResults.enabledBuildersCount == 0 - then "" - else if getBuilderResults.enabledBuildersCount > 1 - then throw "Texlab does not support having more than 1 builders enabled!" - else '' - build = { - executable = "${builder.package}/bin/${builder.executable}", - args = ${listToLua builderArgs false}, - forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, - onSave = ${boolToLua build.onSave}, - useFileList = ${boolToLua build.useFileList}, - auxDirectory = ${stringToLua build.auxDirectory true}, - logDirectory = ${stringToLua build.logDirectory true}, - pdfDirectory = ${stringToLua build.pdfDirectory true}, - filename = ${stringToLua build.filename true}, - }, - ''; - in (mkIf tl.enable { - vim.lsp.lspconfig.sources.texlab = '' - lspconfig.texlab.setup { - cmd = { "${tl.package}/bin/texlab" }, - settings = { - texlab = { - ${buildConfig} - forwardSearch = { - executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", - args = ${listToLua tl.forwardSearch.args true} - }, - ${tl.extraLuaSettings} - } - } - } - ''; - }) - ) - - # Add other LSPs here - ]) + # // (mkMerge [ + # # ----- Texlab ----- + # ( + # let + # tl = cfg.lsp.texlab; + # build = tl.build; + # + # listToLua = list: nullOnEmpty: + # if length list == 0 + # then + # if nullOnEmpty + # then "null" + # else "{ }" + # else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + # + # stringToLua = string: nullOnEmpty: + # if string == "" + # then + # if nullOnEmpty + # then "null" + # else "" + # else ''"${string}"''; + # + # boolToLua = boolean: + # if boolean + # then "true" + # else "false"; + # + # # -- Build -- + # buildConfig = let + # # This function will sort through the builder options of ...texlab.build and count how many + # # builders have been enabled and get the attrs of the last enabled builder. + # getBuilder = { + # enabledBuildersCount ? 0, + # enabledBuilderName ? "", + # index ? 0, + # builderNamesList ? ( + # filter ( + # x: let + # y = tl.build.${x}; + # in (isAttrs y && hasAttr "enable" y) + # ) (attrNames tl.build) + # ), + # }: let + # currentBuilderName = elemAt builderNamesList index; + # currentBuilder = tl.build.${currentBuilderName}; + # nextIndex = index + 1; + # currentState = { + # enabledBuildersCount = + # if currentBuilder.enable + # then enabledBuildersCount + 1 + # else enabledBuildersCount; + # enabledBuilderName = + # if currentBuilder.enable + # then currentBuilderName + # else enabledBuilderName; + # }; + # in + # if length builderNamesList > nextIndex + # then + # getBuilder ({ + # inherit builderNamesList; + # index = nextIndex; + # } + # // currentState) + # else currentState; + # + # getBuilderResults = getBuilder {}; + # builder = tl.build.${getBuilderResults.enabledBuilderName}; + # builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; + # in + # if getBuilderResults.enabledBuildersCount == 0 + # then "" + # else if getBuilderResults.enabledBuildersCount > 1 + # then throw "Texlab does not support having more than 1 builders enabled!" + # else '' + # build = { + # executable = "${builder.package}/bin/${builder.executable}", + # args = ${listToLua builderArgs false}, + # forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, + # onSave = ${boolToLua build.onSave}, + # useFileList = ${boolToLua build.useFileList}, + # auxDirectory = ${stringToLua build.auxDirectory true}, + # logDirectory = ${stringToLua build.logDirectory true}, + # pdfDirectory = ${stringToLua build.pdfDirectory true}, + # filename = ${stringToLua build.filename true}, + # }, + # ''; + # in (mkIf tl.enable { + # vim.lsp.lspconfig.sources.texlab = '' + # lspconfig.texlab.setup { + # cmd = { "${tl.package}/bin/texlab" }, + # settings = { + # texlab = { + # ${buildConfig} + # forwardSearch = { + # executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", + # args = ${listToLua tl.forwardSearch.args true} + # }, + # ${tl.extraLuaSettings} + # } + # } + # } + # ''; + # }) + # ) + # + # # Add other LSPs here + # ]) ); } diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix new file mode 100644 index 00000000..cd7b85dc --- /dev/null +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -0,0 +1,512 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge; + inherit + (lib.types) + bool + either + enum + ints + listOf + oneOf + package + str + ; + inherit (lib.nvim.types) mkGrammarOption; + inherit + (builtins) + any + attrNames + attrValues + concatLists + concatStringsSep + elem + elemAt + filter + hasAttr + isAttrs + length + map + throw + toString + ; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); + mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; + + # --- Arg Collation Functions -- + collateArgs.lsp.texlab.build = { + tectonic = buildConfig: let + selfConfig = buildConfig.tectonic; + in ( + # Base args + [ + "-X" + "compile" + "%f" + ] + # Flags + ++ ( + if selfConfig.keepIntermediates + then ["--keep-intermediates"] + else [] + ) + ++ ( + if selfConfig.keepLogs + then ["--keep-logs"] + else [] + ) + ++ ( + if selfConfig.onlyCached + then ["--only-cached"] + else [] + ) + ++ ( + if selfConfig.synctex + then ["--synctex"] + else [] + ) + ++ ( + if selfConfig.untrustedInput + then ["--untrusted"] + else [] + ) + # Options + ++ ( + if selfConfig.reruns > 0 + then ["--reruns" "${toString selfConfig.reruns}"] + else [] + ) + ++ ( + if selfConfig.bundle != "" + then ["--bundle" "${toString selfConfig.bundle}"] + else [] + ) + ++ ( + if selfConfig.webBundle != "" + then ["--web-bundle" "${toString selfConfig.webBundle}"] + else [] + ) + ++ ( + if selfConfig.outfmt != "" + then ["--outfmt" "${toString selfConfig.outfmt}"] + else [] + ) + ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + ++ ( + if selfConfig.format != "" + then ["--format" "${toString selfConfig.format}"] + else [] + ) + ++ ( + if selfConfig.color != "" + then ["--color" "${toString selfConfig.color}"] + else [] + ) + # 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 buildConfig.pdfDirectory ["." ""]) + then ["--outdir" "${buildConfig.pdfDirectory}"] + else [] + ) + ); + custom = buildConfig: buildConfig.custom.args; + }; +in { + options.vim.languages.tex.lsp.texlab = { + enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; + + package = mkOption { + type = package; + default = pkgs.texlab; + description = "texlab package"; + }; + + build = { + tectonic = { + enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; + + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; + }; + + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # -- Flags -- + keepIntermediates = mkEnableDefaultOption false '' + Keep the intermediate files generated during processing. + + If texlab is reporting build errors when there shouldn't be, disable this option. + ''; + keepLogs = mkEnableDefaultOption true '' + Keep the log files generated during processing. + + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = "Rerun the TeX engine exactly this many times after the first"; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; + }; + + custom = { + enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "build/compiler package"; + }; + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + args = mkOption { + type = listOf str; + default = [ + "-X" + "compile" + "%f" + "--synctex" + "--keep-logs" + "--keep-intermediates" + ]; + description = '' + Defines additional arguments that are passed to the configured LaTeX build tool. + Note that flags and their arguments need to be separate elements in this array. + To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + The placeholder `%f` will be replaced by the server. + + Placeholders: + - `%f`: The path of the TeX file to compile. + ''; + }; + }; + + forwardSearchAfter = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to execute a forward search after a build."; + }; + onSave = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to compile the project after saving a file."; + }; + useFileList = mkOption { + type = bool; + default = false; + description = '' + When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + + Note that enabling this property might have an impact on performance. + ''; + }; + auxDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the .aux files. + Note that you need to set the aux directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + logDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the build log files. + Note that you need to change the output directory in your build arguments too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + pdfDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the output files. + Note that you need to set the output directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + filename = mkOption { + type = str; + default = ""; + 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. + ''; + }; + }; + + forwardSearch = { + enable = mkOption { + type = bool; + default = false; + example = true; + description = '' + Whether to enable forward search. + + Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + + For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + Note this is not all the options, but can act as a guide to help you allong with custom configs. + ''; + }; + package = mkOption { + type = package; + default = pkgs.okular; + description = '' + The package to use as your PDF viewer. + This viewer needs to support Synctex. + ''; + }; + executable = mkOption { + type = str; + default = "okular"; + description = '' + Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + ''; + }; + args = mkOption { + type = listOf str; + default = [ + "--unique" + "file:%p#src:%l%f" + ]; + description = '' + Defines additional arguments that are passed to the configured previewer to perform the forward search. + The placeholders %f, %p, %l will be replaced by the server. + + Placeholders: + - %f: The path of the current TeX file. + - %p: The path of the current PDF file. + - %l: The current line number. + ''; + }; + }; + + extraLuaSettings = mkOption { + type = str; + default = ""; + example = '' + formatterLineLength = 80, + ''; + description = '' + For any options that do not have options provided through nvf this can be used to add them. + Options already declared in nvf config will NOT be overridden. + + Options will be placed in: + ``` + lspconfig.texlab.setup { + settings = { + texlab = { + ... + + ... + + } + } + } + ``` + ''; + }; + }; + + config = mkIf (cfg.enable && (cfg.lsp.texlab.enable)) ( + let + tl = cfg.lsp.texlab; + build = tl.build; + + listToLua = list: nullOnEmpty: + if length list == 0 + then + if nullOnEmpty + then "null" + else "{ }" + else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; + + stringToLua = string: nullOnEmpty: + if string == "" + then + if nullOnEmpty + then "null" + else "" + else ''"${string}"''; + + boolToLua = boolean: + if boolean + then "true" + else "false"; + + # -- Build -- + buildConfig = let + # This function will sort through the builder options of ...texlab.build and count how many + # builders have been enabled and get the attrs of the last enabled builder. + getBuilder = { + enabledBuildersCount ? 0, + enabledBuilderName ? "", + index ? 0, + builderNamesList ? ( + filter ( + x: let + y = tl.build.${x}; + in (isAttrs y && hasAttr "enable" y) + ) (attrNames tl.build) + ), + }: let + currentBuilderName = elemAt builderNamesList index; + currentBuilder = tl.build.${currentBuilderName}; + nextIndex = index + 1; + currentState = { + enabledBuildersCount = + if currentBuilder.enable + then enabledBuildersCount + 1 + else enabledBuildersCount; + enabledBuilderName = + if currentBuilder.enable + then currentBuilderName + else enabledBuilderName; + }; + in + if length builderNamesList > nextIndex + then + getBuilder ({ + inherit builderNamesList; + index = nextIndex; + } + // currentState) + else currentState; + + getBuilderResults = getBuilder {}; + builder = tl.build.${getBuilderResults.enabledBuilderName}; + builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; + in + if getBuilderResults.enabledBuildersCount == 0 + then "" + else if getBuilderResults.enabledBuildersCount > 1 + then throw "Texlab does not support having more than 1 builders enabled!" + else '' + build = { + executable = "${builder.package}/bin/${builder.executable}", + args = ${listToLua builderArgs false}, + forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, + onSave = ${boolToLua build.onSave}, + useFileList = ${boolToLua build.useFileList}, + auxDirectory = ${stringToLua build.auxDirectory true}, + logDirectory = ${stringToLua build.logDirectory true}, + pdfDirectory = ${stringToLua build.pdfDirectory true}, + filename = ${stringToLua build.filename true}, + }, + ''; + in { + vim.lsp.lspconfig.sources.texlab = '' + lspconfig.texlab.setup { + cmd = { "${tl.package}/bin/texlab" }, + settings = { + texlab = { + ${buildConfig} + forwardSearch = { + executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", + args = ${listToLua tl.forwardSearch.args true} + }, + ${tl.extraLuaSettings} + } + } + } + ''; + } + ); +} From 7ebbe28b11a180d3ca17c9571ae4330611dad3f4 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 17:05:25 -0700 Subject: [PATCH 16/65] Cleanup residue from modularization --- modules/plugins/languages/tex/default.nix | 563 +----------------- modules/plugins/languages/tex/lsp/default.nix | 523 +--------------- modules/plugins/languages/tex/lsp/texlab.nix | 22 +- modules/plugins/languages/tex/treesitter.nix | 13 +- 4 files changed, 27 insertions(+), 1094 deletions(-) diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 116403d1..944f43f2 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -1,148 +1,14 @@ -# TODO: -# - Add Texlab LSP settings: -# - chktex -# - diagnosticsDelay -# - diagnostics -# - symbols -# - formatterLineLength -# - bibtexFormatter -# - latexFormatter -# - latexindent -# - completion -# - inlayHints -# - experimental { config, - pkgs, lib, ... }: let - inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit - (lib.types) - bool - either - enum - ints - listOf - oneOf - package - str - ; - inherit (lib.nvim.types) mkGrammarOption; - inherit - (builtins) - any - attrNames - attrValues - concatLists - concatStringsSep - elem - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) bool str; cfg = config.vim.languages.tex; - - # --- Enable Options --- - # mkEnableDefaultOption = default: description: (mkOption { - # type = bool; - # default = default; - # example = !default; - # description = description; - # }); - # mkEnableTreesitterOption = mkEnableDefaultOption config.vim.languages.enableTreesitter; - # mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; - - # # --- Arg Collation Functions -- - # collateArgs.lsp.texlab.build = { - # tectonic = buildConfig: let - # selfConfig = buildConfig.tectonic; - # in ( - # # Base args - # [ - # "-X" - # "compile" - # "%f" - # ] - # # Flags - # ++ ( - # if selfConfig.keepIntermediates - # then ["--keep-intermediates"] - # else [] - # ) - # ++ ( - # if selfConfig.keepLogs - # then ["--keep-logs"] - # else [] - # ) - # ++ ( - # if selfConfig.onlyCached - # then ["--only-cached"] - # else [] - # ) - # ++ ( - # if selfConfig.synctex - # then ["--synctex"] - # else [] - # ) - # ++ ( - # if selfConfig.untrustedInput - # then ["--untrusted"] - # else [] - # ) - # # Options - # ++ ( - # if selfConfig.reruns > 0 - # then ["--reruns" "${toString selfConfig.reruns}"] - # else [] - # ) - # ++ ( - # if selfConfig.bundle != "" - # then ["--bundle" "${toString selfConfig.bundle}"] - # else [] - # ) - # ++ ( - # if selfConfig.webBundle != "" - # then ["--web-bundle" "${toString selfConfig.webBundle}"] - # else [] - # ) - # ++ ( - # if selfConfig.outfmt != "" - # then ["--outfmt" "${toString selfConfig.outfmt}"] - # else [] - # ) - # ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - # ++ ( - # if selfConfig.format != "" - # then ["--format" "${toString selfConfig.format}"] - # else [] - # ) - # ++ ( - # if selfConfig.color != "" - # then ["--color" "${toString selfConfig.color}"] - # else [] - # ) - # # 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 buildConfig.pdfDirectory ["." ""]) - # then ["--outdir" "${buildConfig.pdfDirectory}"] - # else [] - # ) - # ); - # custom = buildConfig: buildConfig.custom.args; - # }; in { - imports = [ ./treesitter.nix ./lsp @@ -151,305 +17,6 @@ in { options.vim.languages.tex = { enable = mkEnableOption "Tex support"; - # # Treesitter options for latex and bibtex flavours of tex. - # treesitter = { - # latex = { - # enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; - # package = mkGrammarOption pkgs "latex"; - # }; - # bibtex = { - # enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; - # package = mkGrammarOption pkgs "bibtex"; - # }; - # }; - - # LSP options - # Because tex LSPs also including building/compiling tex, they have - # more options that are only specific to them and thus it makes - # more sense to group one into its own group of options. - # - # Each lsp group must have an enable option of its own. - # lsp = { - # texlab = { - # enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; - # - # package = mkOption { - # type = package; - # default = pkgs.texlab; - # description = "texlab package"; - # }; - # - # build = { - # tectonic = { - # enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; - # - # package = mkOption { - # type = package; - # default = pkgs.tectonic; - # description = "tectonic package"; - # }; - # - # executable = mkOption { - # type = str; - # default = "tectonic"; - # description = "The executable name from the build package that will be used to build/compile the tex."; - # }; - # - # # -- Flags -- - # keepIntermediates = mkEnableDefaultOption false '' - # Keep the intermediate files generated during processing. - # - # If texlab is reporting build errors when there shouldn't be, disable this option. - # ''; - # keepLogs = mkEnableDefaultOption true '' - # Keep the log files generated during processing. - # - # Without the keepLogs flag, texlab won't be able to report compilation warnings. - # ''; - # onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - # synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - # untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - # - # # -- Options -- - # reruns = mkOption { - # type = ints.unsigned; - # default = 0; - # example = 2; - # description = "Rerun the TeX engine exactly this many times after the first"; - # }; - # - # bundle = mkOption { - # type = str; - # default = ""; - # description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - # }; - # - # webBundle = mkOption { - # type = str; - # default = ""; - # description = "Use this URL to find resource files instead of the default"; - # }; - # - # outfmt = mkOption { - # type = enum [ - # "pdf" - # "html" - # "xdv" - # "aux" - # "fmt" - # "" - # ]; - # default = ""; - # description = "The kind of output to generate"; - # }; - # - # hidePaths = mkOption { - # type = listOf str; - # default = []; - # example = [ - # "./secrets.tex" - # "./passwords.tex" - # ]; - # description = "Tell the engine that no file at exists, if it tries to read it."; - # }; - # - # format = mkOption { - # type = str; - # default = ""; - # description = "The name of the \"format\" file used to initialize the TeX engine"; - # }; - # - # color = mkOption { - # type = enum [ - # "always" - # "auto" - # "never" - # "" - # ]; - # default = ""; - # example = "always"; - # description = "Enable/disable colorful log output"; - # }; - # - # extraOptions = { - # type = listOf str; - # default = []; - # description = '' - # Add extra command line options to include in the tectonic build command. - # Extra options added here will not overwrite the options set in as nvf options. - # ''; - # }; - # }; - # - # custom = { - # enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - # package = mkOption { - # type = package; - # default = pkgs.tectonic; - # description = "build/compiler package"; - # }; - # executable = mkOption { - # type = str; - # default = "tectonic"; - # description = "The executable name from the build package that will be used to build/compile the tex."; - # }; - # args = mkOption { - # type = listOf str; - # default = [ - # "-X" - # "compile" - # "%f" - # "--synctex" - # "--keep-logs" - # "--keep-intermediates" - # ]; - # description = '' - # Defines additional arguments that are passed to the configured LaTeX build tool. - # Note that flags and their arguments need to be separate elements in this array. - # To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - # The placeholder `%f` will be replaced by the server. - # - # Placeholders: - # - `%f`: The path of the TeX file to compile. - # ''; - # }; - # }; - # - # forwardSearchAfter = mkOption { - # type = bool; - # default = false; - # description = "Set this property to true if you want to execute a forward search after a build."; - # }; - # onSave = mkOption { - # type = bool; - # default = false; - # description = "Set this property to true if you want to compile the project after saving a file."; - # }; - # useFileList = mkOption { - # type = bool; - # default = false; - # description = '' - # When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. - # - # Note that enabling this property might have an impact on performance. - # ''; - # }; - # auxDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the .aux files. - # Note that you need to set the aux directory in latex.build.args too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # logDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the build log files. - # Note that you need to change the output directory in your build arguments too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # pdfDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the output files. - # Note that you need to set the output directory in latex.build.args too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # filename = mkOption { - # type = str; - # default = ""; - # 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. - # ''; - # }; - # }; - # - # forwardSearch = { - # enable = mkOption { - # type = bool; - # default = false; - # example = true; - # description = '' - # Whether to enable forward search. - # - # Enable this option if you want to have the compiled document appear in your chosen PDF viewer. - # - # For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - # Note this is not all the options, but can act as a guide to help you allong with custom configs. - # ''; - # }; - # package = mkOption { - # type = package; - # default = pkgs.okular; - # description = '' - # The package to use as your PDF viewer. - # This viewer needs to support Synctex. - # ''; - # }; - # executable = mkOption { - # type = str; - # default = "okular"; - # description = '' - # Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. - # ''; - # }; - # args = mkOption { - # type = listOf str; - # default = [ - # "--unique" - # "file:%p#src:%l%f" - # ]; - # description = '' - # Defines additional arguments that are passed to the configured previewer to perform the forward search. - # The placeholders %f, %p, %l will be replaced by the server. - # - # Placeholders: - # - %f: The path of the current TeX file. - # - %p: The path of the current PDF file. - # - %l: The current line number. - # ''; - # }; - # }; - # - # extraLuaSettings = mkOption { - # type = str; - # default = ""; - # example = '' - # formatterLineLength = 80, - # ''; - # description = '' - # For any options that do not have options provided through nvf this can be used to add them. - # Options already declared in nvf config will NOT be overridden. - # - # Options will be placed in: - # ``` - # lspconfig.texlab.setup { - # settings = { - # texlab = { - # ... - # - # ... - # - # } - # } - # } - # ``` - # ''; - # }; - # }; - # - # # Add other LSPs here - # }; - extraOpts = { texFlavor = { enable = mkOption { @@ -491,132 +58,6 @@ in { }; config = mkIf cfg.enable (mkMerge [ - # # Treesitter - # (mkIf cfg.treesitter.latex.enable { - # vim.treesitter.enable = true; - # vim.treesitter.grammars = [cfg.treesitter.latex.package]; - # }) - # (mkIf cfg.treesitter.bibtex.enable { - # vim.treesitter.enable = true; - # vim.treesitter.grammars = [cfg.treesitter.bibtex.package]; - # }) - - # LSP - # (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( - # { - # vim.lsp.lspconfig.enable = true; - # } # Enable lspconfig when any of the lsps are enabled - # // (mkMerge [ - # # ----- Texlab ----- - # ( - # let - # tl = cfg.lsp.texlab; - # build = tl.build; - # - # listToLua = list: nullOnEmpty: - # if length list == 0 - # then - # if nullOnEmpty - # then "null" - # else "{ }" - # else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; - # - # stringToLua = string: nullOnEmpty: - # if string == "" - # then - # if nullOnEmpty - # then "null" - # else "" - # else ''"${string}"''; - # - # boolToLua = boolean: - # if boolean - # then "true" - # else "false"; - # - # # -- Build -- - # buildConfig = let - # # This function will sort through the builder options of ...texlab.build and count how many - # # builders have been enabled and get the attrs of the last enabled builder. - # getBuilder = { - # enabledBuildersCount ? 0, - # enabledBuilderName ? "", - # index ? 0, - # builderNamesList ? ( - # filter ( - # x: let - # y = tl.build.${x}; - # in (isAttrs y && hasAttr "enable" y) - # ) (attrNames tl.build) - # ), - # }: let - # currentBuilderName = elemAt builderNamesList index; - # currentBuilder = tl.build.${currentBuilderName}; - # nextIndex = index + 1; - # currentState = { - # enabledBuildersCount = - # if currentBuilder.enable - # then enabledBuildersCount + 1 - # else enabledBuildersCount; - # enabledBuilderName = - # if currentBuilder.enable - # then currentBuilderName - # else enabledBuilderName; - # }; - # in - # if length builderNamesList > nextIndex - # then - # getBuilder ({ - # inherit builderNamesList; - # index = nextIndex; - # } - # // currentState) - # else currentState; - # - # getBuilderResults = getBuilder {}; - # builder = tl.build.${getBuilderResults.enabledBuilderName}; - # builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; - # in - # if getBuilderResults.enabledBuildersCount == 0 - # then "" - # else if getBuilderResults.enabledBuildersCount > 1 - # then throw "Texlab does not support having more than 1 builders enabled!" - # else '' - # build = { - # executable = "${builder.package}/bin/${builder.executable}", - # args = ${listToLua builderArgs false}, - # forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, - # onSave = ${boolToLua build.onSave}, - # useFileList = ${boolToLua build.useFileList}, - # auxDirectory = ${stringToLua build.auxDirectory true}, - # logDirectory = ${stringToLua build.logDirectory true}, - # pdfDirectory = ${stringToLua build.pdfDirectory true}, - # filename = ${stringToLua build.filename true}, - # }, - # ''; - # in (mkIf tl.enable { - # vim.lsp.lspconfig.sources.texlab = '' - # lspconfig.texlab.setup { - # cmd = { "${tl.package}/bin/texlab" }, - # settings = { - # texlab = { - # ${buildConfig} - # forwardSearch = { - # executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", - # args = ${listToLua tl.forwardSearch.args true} - # }, - # ${tl.extraLuaSettings} - # } - # } - # } - # ''; - # }) - # ) - # - # # Add other LSPs here - # ]) - # )) - # Extra Lua config options (mkIf cfg.extraOpts.texFlavor.enable { vim.globals.tex_flavor = "${cfg.extraOpts.texFlavor.flavor}"; diff --git a/modules/plugins/languages/tex/lsp/default.nix b/modules/plugins/languages/tex/lsp/default.nix index ffffe5cf..affb272a 100644 --- a/modules/plugins/languages/tex/lsp/default.nix +++ b/modules/plugins/languages/tex/lsp/default.nix @@ -1,531 +1,18 @@ { config, - pkgs, lib, ... }: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.modules) mkIf mkMerge; - inherit - (lib.types) - bool - either - enum - ints - listOf - oneOf - package - str - ; - inherit (lib.nvim.types) mkGrammarOption; - inherit - (builtins) - any - attrNames - attrValues - concatLists - concatStringsSep - elem - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (lib.modules) mkIf; + inherit (builtins) any attrValues; cfg = config.vim.languages.tex; - - # --- Enable Options --- - # mkEnableDefaultOption = default: description: (mkOption { - # type = bool; - # default = default; - # example = !default; - # description = description; - # }); - # mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; - - # # --- Arg Collation Functions -- - # collateArgs.lsp.texlab.build = { - # tectonic = buildConfig: let - # selfConfig = buildConfig.tectonic; - # in ( - # # Base args - # [ - # "-X" - # "compile" - # "%f" - # ] - # # Flags - # ++ ( - # if selfConfig.keepIntermediates - # then ["--keep-intermediates"] - # else [] - # ) - # ++ ( - # if selfConfig.keepLogs - # then ["--keep-logs"] - # else [] - # ) - # ++ ( - # if selfConfig.onlyCached - # then ["--only-cached"] - # else [] - # ) - # ++ ( - # if selfConfig.synctex - # then ["--synctex"] - # else [] - # ) - # ++ ( - # if selfConfig.untrustedInput - # then ["--untrusted"] - # else [] - # ) - # # Options - # ++ ( - # if selfConfig.reruns > 0 - # then ["--reruns" "${toString selfConfig.reruns}"] - # else [] - # ) - # ++ ( - # if selfConfig.bundle != "" - # then ["--bundle" "${toString selfConfig.bundle}"] - # else [] - # ) - # ++ ( - # if selfConfig.webBundle != "" - # then ["--web-bundle" "${toString selfConfig.webBundle}"] - # else [] - # ) - # ++ ( - # if selfConfig.outfmt != "" - # then ["--outfmt" "${toString selfConfig.outfmt}"] - # else [] - # ) - # ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - # ++ ( - # if selfConfig.format != "" - # then ["--format" "${toString selfConfig.format}"] - # else [] - # ) - # ++ ( - # if selfConfig.color != "" - # then ["--color" "${toString selfConfig.color}"] - # else [] - # ) - # # 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 buildConfig.pdfDirectory ["." ""]) - # then ["--outdir" "${buildConfig.pdfDirectory}"] - # else [] - # ) - # ); - # custom = buildConfig: buildConfig.custom.args; - # }; in { imports = [ ./texlab.nix ]; - # options.vim.languages.tex.lsp = { - # texlab = { - # enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; - # - # package = mkOption { - # type = package; - # default = pkgs.texlab; - # description = "texlab package"; - # }; - # - # build = { - # tectonic = { - # enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; - # - # package = mkOption { - # type = package; - # default = pkgs.tectonic; - # description = "tectonic package"; - # }; - # - # executable = mkOption { - # type = str; - # default = "tectonic"; - # description = "The executable name from the build package that will be used to build/compile the tex."; - # }; - # - # # -- Flags -- - # keepIntermediates = mkEnableDefaultOption false '' - # Keep the intermediate files generated during processing. - # - # If texlab is reporting build errors when there shouldn't be, disable this option. - # ''; - # keepLogs = mkEnableDefaultOption true '' - # Keep the log files generated during processing. - # - # Without the keepLogs flag, texlab won't be able to report compilation warnings. - # ''; - # onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - # synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - # untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - # - # # -- Options -- - # reruns = mkOption { - # type = ints.unsigned; - # default = 0; - # example = 2; - # description = "Rerun the TeX engine exactly this many times after the first"; - # }; - # - # bundle = mkOption { - # type = str; - # default = ""; - # description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - # }; - # - # webBundle = mkOption { - # type = str; - # default = ""; - # description = "Use this URL to find resource files instead of the default"; - # }; - # - # outfmt = mkOption { - # type = enum [ - # "pdf" - # "html" - # "xdv" - # "aux" - # "fmt" - # "" - # ]; - # default = ""; - # description = "The kind of output to generate"; - # }; - # - # hidePaths = mkOption { - # type = listOf str; - # default = []; - # example = [ - # "./secrets.tex" - # "./passwords.tex" - # ]; - # description = "Tell the engine that no file at exists, if it tries to read it."; - # }; - # - # format = mkOption { - # type = str; - # default = ""; - # description = "The name of the \"format\" file used to initialize the TeX engine"; - # }; - # - # color = mkOption { - # type = enum [ - # "always" - # "auto" - # "never" - # "" - # ]; - # default = ""; - # example = "always"; - # description = "Enable/disable colorful log output"; - # }; - # - # extraOptions = { - # type = listOf str; - # default = []; - # description = '' - # Add extra command line options to include in the tectonic build command. - # Extra options added here will not overwrite the options set in as nvf options. - # ''; - # }; - # }; - # - # custom = { - # enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - # package = mkOption { - # type = package; - # default = pkgs.tectonic; - # description = "build/compiler package"; - # }; - # executable = mkOption { - # type = str; - # default = "tectonic"; - # description = "The executable name from the build package that will be used to build/compile the tex."; - # }; - # args = mkOption { - # type = listOf str; - # default = [ - # "-X" - # "compile" - # "%f" - # "--synctex" - # "--keep-logs" - # "--keep-intermediates" - # ]; - # description = '' - # Defines additional arguments that are passed to the configured LaTeX build tool. - # Note that flags and their arguments need to be separate elements in this array. - # To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - # The placeholder `%f` will be replaced by the server. - # - # Placeholders: - # - `%f`: The path of the TeX file to compile. - # ''; - # }; - # }; - # - # forwardSearchAfter = mkOption { - # type = bool; - # default = false; - # description = "Set this property to true if you want to execute a forward search after a build."; - # }; - # onSave = mkOption { - # type = bool; - # default = false; - # description = "Set this property to true if you want to compile the project after saving a file."; - # }; - # useFileList = mkOption { - # type = bool; - # default = false; - # description = '' - # When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. - # - # Note that enabling this property might have an impact on performance. - # ''; - # }; - # auxDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the .aux files. - # Note that you need to set the aux directory in latex.build.args too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # logDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the build log files. - # Note that you need to change the output directory in your build arguments too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # pdfDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the output files. - # Note that you need to set the output directory in latex.build.args too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # filename = mkOption { - # type = str; - # default = ""; - # 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. - # ''; - # }; - # }; - # - # forwardSearch = { - # enable = mkOption { - # type = bool; - # default = false; - # example = true; - # description = '' - # Whether to enable forward search. - # - # Enable this option if you want to have the compiled document appear in your chosen PDF viewer. - # - # For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - # Note this is not all the options, but can act as a guide to help you allong with custom configs. - # ''; - # }; - # package = mkOption { - # type = package; - # default = pkgs.okular; - # description = '' - # The package to use as your PDF viewer. - # This viewer needs to support Synctex. - # ''; - # }; - # executable = mkOption { - # type = str; - # default = "okular"; - # description = '' - # Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. - # ''; - # }; - # args = mkOption { - # type = listOf str; - # default = [ - # "--unique" - # "file:%p#src:%l%f" - # ]; - # description = '' - # Defines additional arguments that are passed to the configured previewer to perform the forward search. - # The placeholders %f, %p, %l will be replaced by the server. - # - # Placeholders: - # - %f: The path of the current TeX file. - # - %p: The path of the current PDF file. - # - %l: The current line number. - # ''; - # }; - # }; - # - # extraLuaSettings = mkOption { - # type = str; - # default = ""; - # example = '' - # formatterLineLength = 80, - # ''; - # description = '' - # For any options that do not have options provided through nvf this can be used to add them. - # Options already declared in nvf config will NOT be overridden. - # - # Options will be placed in: - # ``` - # lspconfig.texlab.setup { - # settings = { - # texlab = { - # ... - # - # ... - # - # } - # } - # } - # ``` - # ''; - # }; - # }; - # Add other LSPs here - # }; - - # config = mkIf cfg.enable (mkMerge [ - # (mkIf (any (x: x.enable) (attrValues cfg.lsp)) ( - config = mkIf (cfg.enable && (any (x: x.enable) (attrValues cfg.lsp))) ( - { - vim.lsp.lspconfig.enable = true; - } # Enable lspconfig when any of the lsps are enabled - # // (mkMerge [ - # # ----- Texlab ----- - # ( - # let - # tl = cfg.lsp.texlab; - # build = tl.build; - # - # listToLua = list: nullOnEmpty: - # if length list == 0 - # then - # if nullOnEmpty - # then "null" - # else "{ }" - # else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; - # - # stringToLua = string: nullOnEmpty: - # if string == "" - # then - # if nullOnEmpty - # then "null" - # else "" - # else ''"${string}"''; - # - # boolToLua = boolean: - # if boolean - # then "true" - # else "false"; - # - # # -- Build -- - # buildConfig = let - # # This function will sort through the builder options of ...texlab.build and count how many - # # builders have been enabled and get the attrs of the last enabled builder. - # getBuilder = { - # enabledBuildersCount ? 0, - # enabledBuilderName ? "", - # index ? 0, - # builderNamesList ? ( - # filter ( - # x: let - # y = tl.build.${x}; - # in (isAttrs y && hasAttr "enable" y) - # ) (attrNames tl.build) - # ), - # }: let - # currentBuilderName = elemAt builderNamesList index; - # currentBuilder = tl.build.${currentBuilderName}; - # nextIndex = index + 1; - # currentState = { - # enabledBuildersCount = - # if currentBuilder.enable - # then enabledBuildersCount + 1 - # else enabledBuildersCount; - # enabledBuilderName = - # if currentBuilder.enable - # then currentBuilderName - # else enabledBuilderName; - # }; - # in - # if length builderNamesList > nextIndex - # then - # getBuilder ({ - # inherit builderNamesList; - # index = nextIndex; - # } - # // currentState) - # else currentState; - # - # getBuilderResults = getBuilder {}; - # builder = tl.build.${getBuilderResults.enabledBuilderName}; - # builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; - # in - # if getBuilderResults.enabledBuildersCount == 0 - # then "" - # else if getBuilderResults.enabledBuildersCount > 1 - # then throw "Texlab does not support having more than 1 builders enabled!" - # else '' - # build = { - # executable = "${builder.package}/bin/${builder.executable}", - # args = ${listToLua builderArgs false}, - # forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, - # onSave = ${boolToLua build.onSave}, - # useFileList = ${boolToLua build.useFileList}, - # auxDirectory = ${stringToLua build.auxDirectory true}, - # logDirectory = ${stringToLua build.logDirectory true}, - # pdfDirectory = ${stringToLua build.pdfDirectory true}, - # filename = ${stringToLua build.filename true}, - # }, - # ''; - # in (mkIf tl.enable { - # vim.lsp.lspconfig.sources.texlab = '' - # lspconfig.texlab.setup { - # cmd = { "${tl.package}/bin/texlab" }, - # settings = { - # texlab = { - # ${buildConfig} - # forwardSearch = { - # executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", - # args = ${listToLua tl.forwardSearch.args true} - # }, - # ${tl.extraLuaSettings} - # } - # } - # } - # ''; - # }) - # ) - # - # # Add other LSPs here - # ]) - ); + config = mkIf (cfg.enable && (any (x: x.enable) (attrValues cfg.lsp))) { + vim.lsp.lspconfig.enable = true; # Enable lspconfig when any of the lsps are enabled + }; } diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index cd7b85dc..0f21aa3a 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -1,28 +1,36 @@ +# TODO: +# - Add Texlab LSP settings: +# - chktex +# - diagnosticsDelay +# - diagnostics +# - symbols +# - formatterLineLength +# - bibtexFormatter +# - latexFormatter +# - latexindent +# - completion +# - inlayHints +# - experimental { config, pkgs, lib, ... }: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.modules) mkIf mkMerge; + inherit (lib.options) mkOption; + inherit (lib.modules) mkIf; inherit (lib.types) bool - either enum ints listOf - oneOf package str ; - inherit (lib.nvim.types) mkGrammarOption; inherit (builtins) - any attrNames - attrValues concatLists concatStringsSep elem diff --git a/modules/plugins/languages/tex/treesitter.nix b/modules/plugins/languages/tex/treesitter.nix index 3b70165e..44459afb 100644 --- a/modules/plugins/languages/tex/treesitter.nix +++ b/modules/plugins/languages/tex/treesitter.nix @@ -3,18 +3,15 @@ pkgs, lib, ... -}: -let +}: let inherit (lib.options) mkEnableOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.tex; - mkEnableTreesitterOption = - description: mkEnableOption description // { default = config.vim.languages.enableTreesitter; }; -in -{ + mkEnableTreesitterOption = description: mkEnableOption description // {default = config.vim.languages.enableTreesitter;}; +in { options.vim.languages.tex.treesitter = { latex = { enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; @@ -29,11 +26,11 @@ in config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.latex.enable { vim.treesitter.enable = true; - vim.treesitter.grammars = [ cfg.treesitter.latex.package ]; + vim.treesitter.grammars = [cfg.treesitter.latex.package]; }) (mkIf cfg.treesitter.bibtex.enable { vim.treesitter.enable = true; - vim.treesitter.grammars = [ cfg.treesitter.bibtex.package ]; + vim.treesitter.grammars = [cfg.treesitter.bibtex.package]; }) ]); } From 31f212b5d9e7b6a31a1cf847bd3be9a9e92d5583 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 19:35:00 -0700 Subject: [PATCH 17/65] Created build module --- .../languages/tex/build/builders/custom.nix | 86 +++ .../languages/tex/build/builders/default.nix | 65 ++ .../languages/tex/build/builders/tectonic.nix | 231 +++++++ .../plugins/languages/tex/build/default.nix | 107 +++ modules/plugins/languages/tex/default.nix | 1 + modules/plugins/languages/tex/lsp/texlab.nix | 632 +++++++++--------- 6 files changed, 820 insertions(+), 302 deletions(-) create mode 100644 modules/plugins/languages/tex/build/builders/custom.nix create mode 100644 modules/plugins/languages/tex/build/builders/default.nix create mode 100644 modules/plugins/languages/tex/build/builders/tectonic.nix create mode 100644 modules/plugins/languages/tex/build/default.nix diff --git a/modules/plugins/languages/tex/build/builders/custom.nix b/modules/plugins/languages/tex/build/builders/custom.nix new file mode 100644 index 00000000..680d37a9 --- /dev/null +++ b/modules/plugins/languages/tex/build/builders/custom.nix @@ -0,0 +1,86 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.modules) mkIf; + inherit + (lib.types) + bool + enum + ints + listOf + package + str + ; + inherit + (builtins) + attrNames + concatLists + concatStringsSep + elem + elemAt + filter + hasAttr + isAttrs + length + map + throw + toString + ; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); + + collateArgs = buildConfig: buildConfig.builders.custom.args; +in { + options.vim.languages.tex.build.builders.custom = { + enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "build/compiler package"; + }; + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + args = mkOption { + type = listOf str; + default = [ + "-X" + "compile" + "%f" + "--synctex" + "--keep-logs" + "--keep-intermediates" + ]; + description = '' + Defines additional arguments that are passed to the configured LaTeX build tool. + Note that flags and their arguments need to be separate elements in this array. + To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + The placeholder `%f` will be replaced by the server. + + Placeholders: + - `%f`: The path of the TeX file to compile. + ''; + }; + }; + + config = mkIf (cfg.enable && cfg.build.builders.custom.enable) { + vim.languages.tex.build.builder = { + name = "custom"; + args = collateArgs cfg.build; + }; + }; +} diff --git a/modules/plugins/languages/tex/build/builders/default.nix b/modules/plugins/languages/tex/build/builders/default.nix new file mode 100644 index 00000000..da00fbdb --- /dev/null +++ b/modules/plugins/languages/tex/build/builders/default.nix @@ -0,0 +1,65 @@ +{ + config, + pkgs, + lib, + ... +}: +let + inherit (lib.options) mkOption mkEnableOption; + inherit + (lib.types) + bool + enum + ints + listOf + package + str + ; + inherit + (builtins) + attrNames + concatLists + concatStringsSep + elem + elemAt + filter + hasAttr + isAttrs + length + map + throw + toString + ; + + cfg = config.vim.languages.tex; +in +{ + imports = [ + ./custom.nix + ./tectonic.nix + ]; + + options.vim.languages.tex.build.builder = { + name = mkOption { + type = enum (attrNames cfg.build.builders); + default = "tectonic"; + description = "The tex builder to use"; + }; + args = mkOption { + type = listOf str; + default = []; + description = "The list of args to pass to the builder"; + }; + package = mkOption { + type = package; + default = cfg.build.builders.tectonic.package; + description = "The tex builder package to use"; + }; + executable = mkOption { + type = str; + default = cfg.build.builders.tectonic.executable; + description = "The tex builder executable to use"; + }; + }; +} + diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix new file mode 100644 index 00000000..0ec8bea0 --- /dev/null +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -0,0 +1,231 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.modules) mkIf; + inherit + (lib.types) + bool + enum + ints + listOf + package + str + ; + inherit + (builtins) + attrNames + concatLists + concatStringsSep + elem + elemAt + filter + hasAttr + isAttrs + length + map + throw + toString + ; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); + mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; + + # --- Arg Collation Functions -- + collateArgs = buildConfig: let + selfConfig = buildConfig.builders.tectonic; + in ( + # Base args + [ + "-X" + "compile" + "%f" + ] + # Flags + ++ ( + if selfConfig.keepIntermediates + then ["--keep-intermediates"] + else [] + ) + ++ ( + if selfConfig.keepLogs + then ["--keep-logs"] + else [] + ) + ++ ( + if selfConfig.onlyCached + then ["--only-cached"] + else [] + ) + ++ ( + if selfConfig.synctex + then ["--synctex"] + else [] + ) + ++ ( + if selfConfig.untrustedInput + then ["--untrusted"] + else [] + ) + # Options + ++ ( + if selfConfig.reruns > 0 + then ["--reruns" "${toString selfConfig.reruns}"] + else [] + ) + ++ ( + if selfConfig.bundle != "" + then ["--bundle" "${toString selfConfig.bundle}"] + else [] + ) + ++ ( + if selfConfig.webBundle != "" + then ["--web-bundle" "${toString selfConfig.webBundle}"] + else [] + ) + ++ ( + if selfConfig.outfmt != "" + then ["--outfmt" "${toString selfConfig.outfmt}"] + else [] + ) + ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + ++ ( + if selfConfig.format != "" + then ["--format" "${toString selfConfig.format}"] + else [] + ) + ++ ( + if selfConfig.color != "" + then ["--color" "${toString selfConfig.color}"] + else [] + ) + # 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 buildConfig.pdfDirectory ["." ""]) + then ["--outdir" "${buildConfig.pdfDirectory}"] + else [] + ) + ); +in { + options.vim.languages.tex.build.builders.tectonic = { + enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; + + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; + }; + + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # -- Flags -- + keepIntermediates = mkEnableDefaultOption false '' + Keep the intermediate files generated during processing. + + If texlab is reporting build errors when there shouldn't be, disable this option. + ''; + keepLogs = mkEnableDefaultOption true '' + Keep the log files generated during processing. + + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = "Rerun the TeX engine exactly this many times after the first"; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; + }; + + config = mkIf (cfg.enable && cfg.build.builders.tectonic.enable) { + vim.languages.tex.build.builder = { + name = "tectonic"; + args = collateArgs cfg.build; + package = cfg.build.builders.tectonic.package; + }; + }; +} diff --git a/modules/plugins/languages/tex/build/default.nix b/modules/plugins/languages/tex/build/default.nix new file mode 100644 index 00000000..0882565e --- /dev/null +++ b/modules/plugins/languages/tex/build/default.nix @@ -0,0 +1,107 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.modules) mkIf; + inherit + (lib.types) + bool + enum + ints + listOf + package + str + ; + inherit + (builtins) + attrNames + concatLists + concatStringsSep + elem + elemAt + filter + hasAttr + isAttrs + length + map + throw + toString + ; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); + mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; +in { + imports = [ + ./builders + ]; + + options.vim.languages.tex.build = { + forwardSearchAfter = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to execute a forward search after a build."; + }; + onSave = mkOption { + type = bool; + default = false; + description = "Set this property to true if you want to compile the project after saving a file."; + }; + useFileList = mkOption { + type = bool; + default = false; + description = '' + When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + + Note that enabling this property might have an impact on performance. + ''; + }; + auxDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the .aux files. + Note that you need to set the aux directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + logDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the build log files. + Note that you need to change the output directory in your build arguments too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + pdfDirectory = mkOption { + type = str; + default = "."; + description = '' + When not using latexmk, provides a way to define the directory containing the output files. + Note that you need to set the output directory in latex.build.args too. + + When using a latexmkrc file, texlab will automatically infer the correct setting. + ''; + }; + filename = mkOption { + type = str; + default = ""; + 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. + ''; + }; + }; +} diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 944f43f2..98ac5f1c 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -12,6 +12,7 @@ in { imports = [ ./treesitter.nix ./lsp + ./build ]; options.vim.languages.tex = { diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 0f21aa3a..498a6017 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -56,85 +56,85 @@ mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; # --- Arg Collation Functions -- - collateArgs.lsp.texlab.build = { - tectonic = buildConfig: let - selfConfig = buildConfig.tectonic; - in ( - # Base args - [ - "-X" - "compile" - "%f" - ] - # Flags - ++ ( - if selfConfig.keepIntermediates - then ["--keep-intermediates"] - else [] - ) - ++ ( - if selfConfig.keepLogs - then ["--keep-logs"] - else [] - ) - ++ ( - if selfConfig.onlyCached - then ["--only-cached"] - else [] - ) - ++ ( - if selfConfig.synctex - then ["--synctex"] - else [] - ) - ++ ( - if selfConfig.untrustedInput - then ["--untrusted"] - else [] - ) - # Options - ++ ( - if selfConfig.reruns > 0 - then ["--reruns" "${toString selfConfig.reruns}"] - else [] - ) - ++ ( - if selfConfig.bundle != "" - then ["--bundle" "${toString selfConfig.bundle}"] - else [] - ) - ++ ( - if selfConfig.webBundle != "" - then ["--web-bundle" "${toString selfConfig.webBundle}"] - else [] - ) - ++ ( - if selfConfig.outfmt != "" - then ["--outfmt" "${toString selfConfig.outfmt}"] - else [] - ) - ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - ++ ( - if selfConfig.format != "" - then ["--format" "${toString selfConfig.format}"] - else [] - ) - ++ ( - if selfConfig.color != "" - then ["--color" "${toString selfConfig.color}"] - else [] - ) - # 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 buildConfig.pdfDirectory ["." ""]) - then ["--outdir" "${buildConfig.pdfDirectory}"] - else [] - ) - ); - custom = buildConfig: buildConfig.custom.args; - }; + # collateArgs.lsp.texlab.build = { + # tectonic = buildConfig: let + # selfConfig = buildConfig.tectonic; + # in ( + # # Base args + # [ + # "-X" + # "compile" + # "%f" + # ] + # # Flags + # ++ ( + # if selfConfig.keepIntermediates + # then ["--keep-intermediates"] + # else [] + # ) + # ++ ( + # if selfConfig.keepLogs + # then ["--keep-logs"] + # else [] + # ) + # ++ ( + # if selfConfig.onlyCached + # then ["--only-cached"] + # else [] + # ) + # ++ ( + # if selfConfig.synctex + # then ["--synctex"] + # else [] + # ) + # ++ ( + # if selfConfig.untrustedInput + # then ["--untrusted"] + # else [] + # ) + # # Options + # ++ ( + # if selfConfig.reruns > 0 + # then ["--reruns" "${toString selfConfig.reruns}"] + # else [] + # ) + # ++ ( + # if selfConfig.bundle != "" + # then ["--bundle" "${toString selfConfig.bundle}"] + # else [] + # ) + # ++ ( + # if selfConfig.webBundle != "" + # then ["--web-bundle" "${toString selfConfig.webBundle}"] + # else [] + # ) + # ++ ( + # if selfConfig.outfmt != "" + # then ["--outfmt" "${toString selfConfig.outfmt}"] + # else [] + # ) + # ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + # ++ ( + # if selfConfig.format != "" + # then ["--format" "${toString selfConfig.format}"] + # else [] + # ) + # ++ ( + # if selfConfig.color != "" + # then ["--color" "${toString selfConfig.color}"] + # else [] + # ) + # # 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 buildConfig.pdfDirectory ["." ""]) + # then ["--outdir" "${buildConfig.pdfDirectory}"] + # else [] + # ) + # ); + # custom = buildConfig: buildConfig.custom.args; # Moved + # }; in { options.vim.languages.tex.lsp.texlab = { enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; @@ -145,199 +145,200 @@ in { description = "texlab package"; }; - build = { - tectonic = { - enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; + # build = { + # tectonic = { + # enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; + # + # package = mkOption { + # type = package; + # default = pkgs.tectonic; + # description = "tectonic package"; + # }; + # + # executable = mkOption { + # type = str; + # default = "tectonic"; + # description = "The executable name from the build package that will be used to build/compile the tex."; + # }; + # + # # -- Flags -- + # keepIntermediates = mkEnableDefaultOption false '' + # Keep the intermediate files generated during processing. + # + # If texlab is reporting build errors when there shouldn't be, disable this option. + # ''; + # keepLogs = mkEnableDefaultOption true '' + # Keep the log files generated during processing. + # + # Without the keepLogs flag, texlab won't be able to report compilation warnings. + # ''; + # onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + # synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + # untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + # + # # -- Options -- + # reruns = mkOption { + # type = ints.unsigned; + # default = 0; + # example = 2; + # description = "Rerun the TeX engine exactly this many times after the first"; + # }; + # + # bundle = mkOption { + # type = str; + # default = ""; + # description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + # }; + # + # webBundle = mkOption { + # type = str; + # default = ""; + # description = "Use this URL to find resource files instead of the default"; + # }; + # + # outfmt = mkOption { + # type = enum [ + # "pdf" + # "html" + # "xdv" + # "aux" + # "fmt" + # "" + # ]; + # default = ""; + # description = "The kind of output to generate"; + # }; + # + # hidePaths = mkOption { + # type = listOf str; + # default = []; + # example = [ + # "./secrets.tex" + # "./passwords.tex" + # ]; + # description = "Tell the engine that no file at exists, if it tries to read it."; + # }; + # + # format = mkOption { + # type = str; + # default = ""; + # description = "The name of the \"format\" file used to initialize the TeX engine"; + # }; + # + # color = mkOption { + # type = enum [ + # "always" + # "auto" + # "never" + # "" + # ]; + # default = ""; + # example = "always"; + # description = "Enable/disable colorful log output"; + # }; + # + # extraOptions = { + # type = listOf str; + # default = []; + # description = '' + # Add extra command line options to include in the tectonic build command. + # Extra options added here will not overwrite the options set in as nvf options. + # ''; + # }; + # }; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; + # # Moved + # custom = { + # enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; + # package = mkOption { + # type = package; + # default = pkgs.tectonic; + # description = "build/compiler package"; + # }; + # executable = mkOption { + # type = str; + # default = "tectonic"; + # description = "The executable name from the build package that will be used to build/compile the tex."; + # }; + # args = mkOption { + # type = listOf str; + # default = [ + # "-X" + # "compile" + # "%f" + # "--synctex" + # "--keep-logs" + # "--keep-intermediates" + # ]; + # description = '' + # Defines additional arguments that are passed to the configured LaTeX build tool. + # Note that flags and their arguments need to be separate elements in this array. + # To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. + # The placeholder `%f` will be replaced by the server. + # + # Placeholders: + # - `%f`: The path of the TeX file to compile. + # ''; + # }; + # }; - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - - # -- Flags -- - keepIntermediates = mkEnableDefaultOption false '' - Keep the intermediate files generated during processing. - - If texlab is reporting build errors when there shouldn't be, disable this option. - ''; - keepLogs = mkEnableDefaultOption true '' - Keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation warnings. - ''; - onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = "Rerun the TeX engine exactly this many times after the first"; - }; - - bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - }; - - webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; - }; - - outfmt = mkOption { - type = enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = "Tell the engine that no file at exists, if it tries to read it."; - }; - - format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; - }; - - color = mkOption { - type = enum [ - "always" - "auto" - "never" - "" - ]; - default = ""; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. - ''; - }; - }; - - custom = { - enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "build/compiler package"; - }; - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - args = mkOption { - type = listOf str; - default = [ - "-X" - "compile" - "%f" - "--synctex" - "--keep-logs" - "--keep-intermediates" - ]; - description = '' - Defines additional arguments that are passed to the configured LaTeX build tool. - Note that flags and their arguments need to be separate elements in this array. - To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - The placeholder `%f` will be replaced by the server. - - Placeholders: - - `%f`: The path of the TeX file to compile. - ''; - }; - }; - - forwardSearchAfter = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to execute a forward search after a build."; - }; - onSave = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to compile the project after saving a file."; - }; - useFileList = mkOption { - type = bool; - default = false; - description = '' - When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. - - Note that enabling this property might have an impact on performance. - ''; - }; - auxDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the .aux files. - Note that you need to set the aux directory in latex.build.args too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - logDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the build log files. - Note that you need to change the output directory in your build arguments too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - pdfDirectory = mkOption { - type = str; - default = "."; - description = '' - When not using latexmk, provides a way to define the directory containing the output files. - Note that you need to set the output directory in latex.build.args too. - - When using a latexmkrc file, texlab will automatically infer the correct setting. - ''; - }; - filename = mkOption { - type = str; - default = ""; - 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. - ''; - }; - }; + # forwardSearchAfter = mkOption { + # type = bool; + # default = false; + # description = "Set this property to true if you want to execute a forward search after a build."; + # }; + # onSave = mkOption { + # type = bool; + # default = false; + # description = "Set this property to true if you want to compile the project after saving a file."; + # }; + # useFileList = mkOption { + # type = bool; + # default = false; + # description = '' + # When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + # + # Note that enabling this property might have an impact on performance. + # ''; + # }; + # auxDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the .aux files. + # Note that you need to set the aux directory in latex.build.args too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # logDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the build log files. + # Note that you need to change the output directory in your build arguments too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # pdfDirectory = mkOption { + # type = str; + # default = "."; + # description = '' + # When not using latexmk, provides a way to define the directory containing the output files. + # Note that you need to set the output directory in latex.build.args too. + # + # When using a latexmkrc file, texlab will automatically infer the correct setting. + # ''; + # }; + # filename = mkOption { + # type = str; + # default = ""; + # 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. + # ''; + # }; + # }; forwardSearch = { enable = mkOption { @@ -416,7 +417,7 @@ in { config = mkIf (cfg.enable && (cfg.lsp.texlab.enable)) ( let tl = cfg.lsp.texlab; - build = tl.build; + builder = cfg.build.builder; listToLua = list: nullOnEmpty: if length list == 0 @@ -443,60 +444,87 @@ in { buildConfig = let # This function will sort through the builder options of ...texlab.build and count how many # builders have been enabled and get the attrs of the last enabled builder. - getBuilder = { + # getBuilder = { + # enabledBuildersCount ? 0, + # enabledBuilderName ? "", + # index ? 0, + # builderNamesList ? ( + # filter ( + # x: let + # y = cfg.build.builders.${x}; + # in (isAttrs y && hasAttr "enable" y) + # ) (attrNames cfg.build.builders) + # ), + # }: let + # currentBuilderName = elemAt builderNamesList index; + # currentBuilder = tl.build.${currentBuilderName}; + # nextIndex = index + 1; + # currentState = { + # enabledBuildersCount = + # if currentBuilder.enable + # then enabledBuildersCount + 1 + # else enabledBuildersCount; + # enabledBuilderName = + # if currentBuilder.enable + # then currentBuilderName + # else enabledBuilderName; + # }; + # in + # if length builderNamesList > nextIndex + # then + # getBuilder ({ + # inherit builderNamesList; + # index = nextIndex; + # } + # // currentState) + # else currentState; + getEnabledBuildersCount = { enabledBuildersCount ? 0, - enabledBuilderName ? "", index ? 0, builderNamesList ? ( filter ( x: let - y = tl.build.${x}; + y = cfg.build.builders.${x}; in (isAttrs y && hasAttr "enable" y) - ) (attrNames tl.build) + ) (attrNames cfg.build.builders) ), }: let currentBuilderName = elemAt builderNamesList index; - currentBuilder = tl.build.${currentBuilderName}; + currentBuilder = cfg.build.builders.${currentBuilderName}; nextIndex = index + 1; - currentState = { - enabledBuildersCount = - if currentBuilder.enable - then enabledBuildersCount + 1 - else enabledBuildersCount; - enabledBuilderName = - if currentBuilder.enable - then currentBuilderName - else enabledBuilderName; - }; + newEnabledBuildersCount = + if currentBuilder.enable + then enabledBuildersCount + 1 + else enabledBuildersCount; in if length builderNamesList > nextIndex then - getBuilder ({ + getEnabledBuildersCount { inherit builderNamesList; + enabledBuildersCount = newEnabledBuildersCount; index = nextIndex; } - // currentState) - else currentState; + else newEnabledBuildersCount; - getBuilderResults = getBuilder {}; - builder = tl.build.${getBuilderResults.enabledBuilderName}; - builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; + enabledBuildersCount = getEnabledBuildersCount {}; + # builder = tl.build.${getBuilderResults.enabledBuilderName}; + # builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; in - if getBuilderResults.enabledBuildersCount == 0 + if enabledBuildersCount == 0 then "" - else if getBuilderResults.enabledBuildersCount > 1 + else if enabledBuildersCount > 1 then throw "Texlab does not support having more than 1 builders enabled!" else '' build = { executable = "${builder.package}/bin/${builder.executable}", - args = ${listToLua builderArgs false}, - forwardSearchAfter = ${boolToLua build.forwardSearchAfter}, - onSave = ${boolToLua build.onSave}, - useFileList = ${boolToLua build.useFileList}, - auxDirectory = ${stringToLua build.auxDirectory true}, - logDirectory = ${stringToLua build.logDirectory true}, - pdfDirectory = ${stringToLua build.pdfDirectory true}, - filename = ${stringToLua build.filename true}, + args = ${listToLua builder.args false}, + forwardSearchAfter = ${boolToLua cfg.build.forwardSearchAfter}, + onSave = ${boolToLua cfg.build.onSave}, + useFileList = ${boolToLua cfg.build.useFileList}, + auxDirectory = ${stringToLua cfg.build.auxDirectory true}, + logDirectory = ${stringToLua cfg.build.logDirectory true}, + pdfDirectory = ${stringToLua cfg.build.pdfDirectory true}, + filename = ${stringToLua cfg.build.filename true}, }, ''; in { From 2c856dcd64240629c4c521c9542cd212a625c8b7 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 19:44:59 -0700 Subject: [PATCH 18/65] Cleanup after makeing build module --- .../languages/tex/build/builders/custom.nix | 27 +- .../languages/tex/build/builders/default.nix | 29 +- .../languages/tex/build/builders/tectonic.nix | 18 +- .../plugins/languages/tex/build/default.nix | 36 +- modules/plugins/languages/tex/lsp/texlab.nix | 328 +----------------- 5 files changed, 15 insertions(+), 423 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/custom.nix b/modules/plugins/languages/tex/build/builders/custom.nix index 680d37a9..749bf6be 100644 --- a/modules/plugins/languages/tex/build/builders/custom.nix +++ b/modules/plugins/languages/tex/build/builders/custom.nix @@ -6,30 +6,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit - (lib.types) - bool - enum - ints - listOf - package - str - ; - inherit - (builtins) - attrNames - concatLists - concatStringsSep - elem - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (lib.types) bool listOf package str ; cfg = config.vim.languages.tex; @@ -81,6 +58,8 @@ in { vim.languages.tex.build.builder = { name = "custom"; args = collateArgs cfg.build; + package = cfg.build.builders.custom.package; + executable = cfg.build.builders.custom.executable; }; }; } diff --git a/modules/plugins/languages/tex/build/builders/default.nix b/modules/plugins/languages/tex/build/builders/default.nix index da00fbdb..d772bb04 100644 --- a/modules/plugins/languages/tex/build/builders/default.nix +++ b/modules/plugins/languages/tex/build/builders/default.nix @@ -1,35 +1,12 @@ { config, - pkgs, lib, ... }: let - inherit (lib.options) mkOption mkEnableOption; - inherit - (lib.types) - bool - enum - ints - listOf - package - str - ; - inherit - (builtins) - attrNames - concatLists - concatStringsSep - elem - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (lib.options) mkOption; + inherit (lib.types) enum listOf package str; + inherit (builtins) attrNames; cfg = config.vim.languages.tex; in diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 0ec8bea0..29188cf2 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -15,21 +15,7 @@ package str ; - inherit - (builtins) - attrNames - concatLists - concatStringsSep - elem - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (builtins) concatLists elem map toString; cfg = config.vim.languages.tex; @@ -40,7 +26,6 @@ example = !default; description = description; }); - mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; # --- Arg Collation Functions -- collateArgs = buildConfig: let @@ -226,6 +211,7 @@ in { name = "tectonic"; args = collateArgs cfg.build; package = cfg.build.builders.tectonic.package; + executable = cfg.build.builders.tectonic.package; }; }; } diff --git a/modules/plugins/languages/tex/build/default.nix b/modules/plugins/languages/tex/build/default.nix index 0882565e..cbc9dca7 100644 --- a/modules/plugins/languages/tex/build/default.nix +++ b/modules/plugins/languages/tex/build/default.nix @@ -1,46 +1,12 @@ { config, - pkgs, lib, ... }: let inherit (lib.options) mkOption; - inherit (lib.modules) mkIf; - inherit - (lib.types) - bool - enum - ints - listOf - package - str - ; - inherit - (builtins) - attrNames - concatLists - concatStringsSep - elem - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (lib.types) bool str; cfg = config.vim.languages.tex; - - # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); - mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; in { imports = [ ./builders diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 498a6017..fd319a6d 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -22,8 +22,6 @@ inherit (lib.types) bool - enum - ints listOf package str @@ -31,9 +29,7 @@ inherit (builtins) attrNames - concatLists concatStringsSep - elem elemAt filter hasAttr @@ -54,87 +50,6 @@ description = description; }); mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; - - # --- Arg Collation Functions -- - # collateArgs.lsp.texlab.build = { - # tectonic = buildConfig: let - # selfConfig = buildConfig.tectonic; - # in ( - # # Base args - # [ - # "-X" - # "compile" - # "%f" - # ] - # # Flags - # ++ ( - # if selfConfig.keepIntermediates - # then ["--keep-intermediates"] - # else [] - # ) - # ++ ( - # if selfConfig.keepLogs - # then ["--keep-logs"] - # else [] - # ) - # ++ ( - # if selfConfig.onlyCached - # then ["--only-cached"] - # else [] - # ) - # ++ ( - # if selfConfig.synctex - # then ["--synctex"] - # else [] - # ) - # ++ ( - # if selfConfig.untrustedInput - # then ["--untrusted"] - # else [] - # ) - # # Options - # ++ ( - # if selfConfig.reruns > 0 - # then ["--reruns" "${toString selfConfig.reruns}"] - # else [] - # ) - # ++ ( - # if selfConfig.bundle != "" - # then ["--bundle" "${toString selfConfig.bundle}"] - # else [] - # ) - # ++ ( - # if selfConfig.webBundle != "" - # then ["--web-bundle" "${toString selfConfig.webBundle}"] - # else [] - # ) - # ++ ( - # if selfConfig.outfmt != "" - # then ["--outfmt" "${toString selfConfig.outfmt}"] - # else [] - # ) - # ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - # ++ ( - # if selfConfig.format != "" - # then ["--format" "${toString selfConfig.format}"] - # else [] - # ) - # ++ ( - # if selfConfig.color != "" - # then ["--color" "${toString selfConfig.color}"] - # else [] - # ) - # # 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 buildConfig.pdfDirectory ["." ""]) - # then ["--outdir" "${buildConfig.pdfDirectory}"] - # else [] - # ) - # ); - # custom = buildConfig: buildConfig.custom.args; # Moved - # }; in { options.vim.languages.tex.lsp.texlab = { enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; @@ -145,201 +60,6 @@ in { description = "texlab package"; }; - # build = { - # tectonic = { - # enable = mkEnableDefaultOption true "Whether to enable Tex Compilation Via Tectonic"; - # - # package = mkOption { - # type = package; - # default = pkgs.tectonic; - # description = "tectonic package"; - # }; - # - # executable = mkOption { - # type = str; - # default = "tectonic"; - # description = "The executable name from the build package that will be used to build/compile the tex."; - # }; - # - # # -- Flags -- - # keepIntermediates = mkEnableDefaultOption false '' - # Keep the intermediate files generated during processing. - # - # If texlab is reporting build errors when there shouldn't be, disable this option. - # ''; - # keepLogs = mkEnableDefaultOption true '' - # Keep the log files generated during processing. - # - # Without the keepLogs flag, texlab won't be able to report compilation warnings. - # ''; - # onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - # synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - # untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - # - # # -- Options -- - # reruns = mkOption { - # type = ints.unsigned; - # default = 0; - # example = 2; - # description = "Rerun the TeX engine exactly this many times after the first"; - # }; - # - # bundle = mkOption { - # type = str; - # default = ""; - # description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - # }; - # - # webBundle = mkOption { - # type = str; - # default = ""; - # description = "Use this URL to find resource files instead of the default"; - # }; - # - # outfmt = mkOption { - # type = enum [ - # "pdf" - # "html" - # "xdv" - # "aux" - # "fmt" - # "" - # ]; - # default = ""; - # description = "The kind of output to generate"; - # }; - # - # hidePaths = mkOption { - # type = listOf str; - # default = []; - # example = [ - # "./secrets.tex" - # "./passwords.tex" - # ]; - # description = "Tell the engine that no file at exists, if it tries to read it."; - # }; - # - # format = mkOption { - # type = str; - # default = ""; - # description = "The name of the \"format\" file used to initialize the TeX engine"; - # }; - # - # color = mkOption { - # type = enum [ - # "always" - # "auto" - # "never" - # "" - # ]; - # default = ""; - # example = "always"; - # description = "Enable/disable colorful log output"; - # }; - # - # extraOptions = { - # type = listOf str; - # default = []; - # description = '' - # Add extra command line options to include in the tectonic build command. - # Extra options added here will not overwrite the options set in as nvf options. - # ''; - # }; - # }; - - # # Moved - # custom = { - # enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - # package = mkOption { - # type = package; - # default = pkgs.tectonic; - # description = "build/compiler package"; - # }; - # executable = mkOption { - # type = str; - # default = "tectonic"; - # description = "The executable name from the build package that will be used to build/compile the tex."; - # }; - # args = mkOption { - # type = listOf str; - # default = [ - # "-X" - # "compile" - # "%f" - # "--synctex" - # "--keep-logs" - # "--keep-intermediates" - # ]; - # description = '' - # Defines additional arguments that are passed to the configured LaTeX build tool. - # Note that flags and their arguments need to be separate elements in this array. - # To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - # The placeholder `%f` will be replaced by the server. - # - # Placeholders: - # - `%f`: The path of the TeX file to compile. - # ''; - # }; - # }; - - # forwardSearchAfter = mkOption { - # type = bool; - # default = false; - # description = "Set this property to true if you want to execute a forward search after a build."; - # }; - # onSave = mkOption { - # type = bool; - # default = false; - # description = "Set this property to true if you want to compile the project after saving a file."; - # }; - # useFileList = mkOption { - # type = bool; - # default = false; - # description = '' - # When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. - # - # Note that enabling this property might have an impact on performance. - # ''; - # }; - # auxDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the .aux files. - # Note that you need to set the aux directory in latex.build.args too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # logDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the build log files. - # Note that you need to change the output directory in your build arguments too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # pdfDirectory = mkOption { - # type = str; - # default = "."; - # description = '' - # When not using latexmk, provides a way to define the directory containing the output files. - # Note that you need to set the output directory in latex.build.args too. - # - # When using a latexmkrc file, texlab will automatically infer the correct setting. - # ''; - # }; - # filename = mkOption { - # type = str; - # default = ""; - # 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. - # ''; - # }; - # }; - forwardSearch = { enable = mkOption { type = bool; @@ -442,42 +162,8 @@ in { # -- Build -- buildConfig = let - # This function will sort through the builder options of ...texlab.build and count how many - # builders have been enabled and get the attrs of the last enabled builder. - # getBuilder = { - # enabledBuildersCount ? 0, - # enabledBuilderName ? "", - # index ? 0, - # builderNamesList ? ( - # filter ( - # x: let - # y = cfg.build.builders.${x}; - # in (isAttrs y && hasAttr "enable" y) - # ) (attrNames cfg.build.builders) - # ), - # }: let - # currentBuilderName = elemAt builderNamesList index; - # currentBuilder = tl.build.${currentBuilderName}; - # nextIndex = index + 1; - # currentState = { - # enabledBuildersCount = - # if currentBuilder.enable - # then enabledBuildersCount + 1 - # else enabledBuildersCount; - # enabledBuilderName = - # if currentBuilder.enable - # then currentBuilderName - # else enabledBuilderName; - # }; - # in - # if length builderNamesList > nextIndex - # then - # getBuilder ({ - # inherit builderNamesList; - # index = nextIndex; - # } - # // currentState) - # else currentState; + # This function will sort through the builder options and count how many + # builders have been enabled. getEnabledBuildersCount = { enabledBuildersCount ? 0, index ? 0, @@ -500,15 +186,13 @@ in { if length builderNamesList > nextIndex then getEnabledBuildersCount { - inherit builderNamesList; - enabledBuildersCount = newEnabledBuildersCount; - index = nextIndex; - } + inherit builderNamesList; + enabledBuildersCount = newEnabledBuildersCount; + index = nextIndex; + } else newEnabledBuildersCount; enabledBuildersCount = getEnabledBuildersCount {}; - # builder = tl.build.${getBuilderResults.enabledBuilderName}; - # builderArgs = collateArgs.lsp.texlab.build.${getBuilderResults.enabledBuilderName} tl.build; in if enabledBuildersCount == 0 then "" From 77bb18fe080cde8ca8de8a13e3adae1cf1300d6d Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 23 Jan 2025 19:50:17 -0700 Subject: [PATCH 19/65] Fixed typo --- modules/plugins/languages/tex/build/builders/tectonic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 29188cf2..82f4b8b2 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -211,7 +211,7 @@ in { name = "tectonic"; args = collateArgs cfg.build; package = cfg.build.builders.tectonic.package; - executable = cfg.build.builders.tectonic.package; + executable = cfg.build.builders.tectonic.executable; }; }; } From 2e5544214bdb3246c8a83809f424d497ee67466c Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Fri, 24 Jan 2025 10:28:17 -0700 Subject: [PATCH 20/65] Created builder template for making new builders that will work with existing code --- .../tex/build/builders/builderTemplate.nix | 67 ++++ .../builders/{custom.nix => custom.nix.bak} | 11 +- .../languages/tex/build/builders/default.nix | 46 ++- .../languages/tex/build/builders/tectonic.nix | 373 +++++++++--------- .../tex/build/builders/tectonic.nix.bak | 217 ++++++++++ 5 files changed, 508 insertions(+), 206 deletions(-) create mode 100644 modules/plugins/languages/tex/build/builders/builderTemplate.nix rename modules/plugins/languages/tex/build/builders/{custom.nix => custom.nix.bak} (85%) create mode 100644 modules/plugins/languages/tex/build/builders/tectonic.nix.bak diff --git a/modules/plugins/languages/tex/build/builders/builderTemplate.nix b/modules/plugins/languages/tex/build/builders/builderTemplate.nix new file mode 100644 index 00000000..3d3f607f --- /dev/null +++ b/modules/plugins/languages/tex/build/builders/builderTemplate.nix @@ -0,0 +1,67 @@ +# This function acts as a template for creating new builders. +# It enforces providing all the parameters required for creating +# a new builder for it to be able to work in the existing code. + +# The first layer requirements are as follows: +{ + # This is the name of the builder, it will only be used internally and + # should match the .nix file that the builder is implemented in. + name, + + # Module attribute set. This is the attribute set that the module that is + # defining a builder is passed as its input. + moduleInheritencePackage, + + # These are the standard options for the builder just like creating any + # other module. Some options are required and are described below but + # it will also accept any other options that are provided to it. + options, + + # These are the command line arguments that will accompany the executable + # when the build command is called. + # This is a function that will take in the cfg of its own builder. + # i.e. will be called as "args cfg.build.builders.${name}" + args, + + ... +}: let + # Inherit the necessary variables available to any module. + inherit (moduleInheritencePackage) lib config; + + # Inherit other useful functions. + inherit (lib.modules) mkIf; + + # Set the cfg variable + cfg = config.vim.languages.tex; +in { + # These are the options for the builder. It will accept any options + # provided to it but some options are mandatory: + options.vim.languages.tex.build.builders.${name} = ({ + # The enable option. This one is self explanatory. + enable, + + # This is the package option for the builder. + package, + + # This is the executable that will be used to call the builder. + # It, along with package will result in: + # "/bin/" + executable, + + # Any other options provided are accepted. + ... + } @ opts: + opts) + options; + + # Check that the language and this builder have been enabled + # before making any config. + config = mkIf (cfg.enable && cfg.build.builders.${name}.enable) { + vim.languages.tex.build.builder = { + inherit name; + package = cfg.build.builders.${name}.package; + executable = cfg.build.builders.${name}.executable; + args = args cfg.build.builders.${name}; + }; + }; +} diff --git a/modules/plugins/languages/tex/build/builders/custom.nix b/modules/plugins/languages/tex/build/builders/custom.nix.bak similarity index 85% rename from modules/plugins/languages/tex/build/builders/custom.nix rename to modules/plugins/languages/tex/build/builders/custom.nix.bak index 749bf6be..01b5913c 100644 --- a/modules/plugins/languages/tex/build/builders/custom.nix +++ b/modules/plugins/languages/tex/build/builders/custom.nix.bak @@ -6,7 +6,8 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit (lib.types) bool listOf package str ; + inherit (lib.types) bool listOf package str; + inherit (lib) mkDefault; cfg = config.vim.languages.tex; @@ -56,10 +57,10 @@ in { config = mkIf (cfg.enable && cfg.build.builders.custom.enable) { vim.languages.tex.build.builder = { - name = "custom"; - args = collateArgs cfg.build; - package = cfg.build.builders.custom.package; - executable = cfg.build.builders.custom.executable; + name = mkDefault "custom"; + args = mkDefault (collateArgs cfg.build); + package = mkDefault (cfg.build.builders.custom.package); + executable = mkDefault (cfg.build.builders.custom.executable); }; }; } diff --git a/modules/plugins/languages/tex/build/builders/default.nix b/modules/plugins/languages/tex/build/builders/default.nix index d772bb04..3e9eca59 100644 --- a/modules/plugins/languages/tex/build/builders/default.nix +++ b/modules/plugins/languages/tex/build/builders/default.nix @@ -1,5 +1,6 @@ { config, + pkgs, lib, ... }: @@ -12,30 +13,57 @@ let in { imports = [ - ./custom.nix + # ./custom.nix ./tectonic.nix ]; options.vim.languages.tex.build.builder = { name = mkOption { type = enum (attrNames cfg.build.builders); - default = "tectonic"; - description = "The tex builder to use"; + default = "latexmk"; + description = '' + The tex builder to use. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; }; args = mkOption { type = listOf str; - default = []; - description = "The list of args to pass to the builder"; + default = [ + "-pdf" + "%f" + ]; + description = '' + The list of args to pass to the builder. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; }; package = mkOption { type = package; - default = cfg.build.builders.tectonic.package; - description = "The tex builder package to use"; + default = (pkgs.texlive.withPackages (ps: [ ps.latexmk ])); + description = '' + The tex builder package to use. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; }; executable = mkOption { type = str; - default = cfg.build.builders.tectonic.executable; - description = "The tex builder executable to use"; + default = "latexmk"; + description = '' + The tex builder executable to use. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; }; }; } diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 82f4b8b2..71facf1e 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -3,18 +3,15 @@ pkgs, lib, ... -}: let +} @ moduleInheritencePackage: let + # The name of the builder + name = "tectonic"; + + # The builder template + template = import ./builderTemplate.nix; + inherit (lib.options) mkOption mkEnableOption; - inherit (lib.modules) mkIf; - inherit - (lib.types) - bool - enum - ints - listOf - package - str - ; + inherit (lib.types) bool enum ints listOf package str; inherit (builtins) concatLists elem map toString; cfg = config.vim.languages.tex; @@ -26,192 +23,184 @@ example = !default; description = description; }); +in ( + template { + inherit name moduleInheritencePackage; - # --- Arg Collation Functions -- - collateArgs = buildConfig: let - selfConfig = buildConfig.builders.tectonic; - in ( - # Base args - [ - "-X" - "compile" - "%f" - ] - # Flags - ++ ( - if selfConfig.keepIntermediates - then ["--keep-intermediates"] - else [] - ) - ++ ( - if selfConfig.keepLogs - then ["--keep-logs"] - else [] - ) - ++ ( - if selfConfig.onlyCached - then ["--only-cached"] - else [] - ) - ++ ( - if selfConfig.synctex - then ["--synctex"] - else [] - ) - ++ ( - if selfConfig.untrustedInput - then ["--untrusted"] - else [] - ) - # Options - ++ ( - if selfConfig.reruns > 0 - then ["--reruns" "${toString selfConfig.reruns}"] - else [] - ) - ++ ( - if selfConfig.bundle != "" - then ["--bundle" "${toString selfConfig.bundle}"] - else [] - ) - ++ ( - if selfConfig.webBundle != "" - then ["--web-bundle" "${toString selfConfig.webBundle}"] - else [] - ) - ++ ( - if selfConfig.outfmt != "" - then ["--outfmt" "${toString selfConfig.outfmt}"] - else [] - ) - ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - ++ ( - if selfConfig.format != "" - then ["--format" "${toString selfConfig.format}"] - else [] - ) - ++ ( - if selfConfig.color != "" - then ["--color" "${toString selfConfig.color}"] - else [] - ) - # 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 buildConfig.pdfDirectory ["." ""]) - then ["--outdir" "${buildConfig.pdfDirectory}"] - else [] - ) - ); -in { - options.vim.languages.tex.build.builders.tectonic = { - enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; + options = { + enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; + }; - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; - # -- Flags -- - keepIntermediates = mkEnableDefaultOption false '' - Keep the intermediate files generated during processing. + # -- Flags -- + keepIntermediates = mkEnableDefaultOption false '' + Keep the intermediate files generated during processing. - If texlab is reporting build errors when there shouldn't be, disable this option. - ''; - keepLogs = mkEnableDefaultOption true '' - Keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation warnings. - ''; - onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = "Rerun the TeX engine exactly this many times after the first"; - }; - - bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - }; - - webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; - }; - - outfmt = mkOption { - type = enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = "Tell the engine that no file at exists, if it tries to read it."; - }; - - format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; - }; - - color = mkOption { - type = enum [ - "always" - "auto" - "never" - "" - ]; - default = ""; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. + If texlab is reporting build errors when there shouldn't be, disable this option. ''; - }; - }; + keepLogs = mkEnableDefaultOption true '' + Keep the log files generated during processing. - config = mkIf (cfg.enable && cfg.build.builders.tectonic.enable) { - vim.languages.tex.build.builder = { - name = "tectonic"; - args = collateArgs cfg.build; - package = cfg.build.builders.tectonic.package; - executable = cfg.build.builders.tectonic.executable; + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = "Rerun the TeX engine exactly this many times after the first"; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; }; - }; -} + + args = builderCfg: ( + # Base args + [ + "-X" + "compile" + "%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 [] + ) + # 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 [] + ) + ++ (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 [] + ) + # 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 [] + ) + ); + } +) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix.bak b/modules/plugins/languages/tex/build/builders/tectonic.nix.bak new file mode 100644 index 00000000..82f4b8b2 --- /dev/null +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix.bak @@ -0,0 +1,217 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.modules) mkIf; + inherit + (lib.types) + bool + enum + ints + listOf + package + str + ; + inherit (builtins) concatLists elem map toString; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); + + # --- Arg Collation Functions -- + collateArgs = buildConfig: let + selfConfig = buildConfig.builders.tectonic; + in ( + # Base args + [ + "-X" + "compile" + "%f" + ] + # Flags + ++ ( + if selfConfig.keepIntermediates + then ["--keep-intermediates"] + else [] + ) + ++ ( + if selfConfig.keepLogs + then ["--keep-logs"] + else [] + ) + ++ ( + if selfConfig.onlyCached + then ["--only-cached"] + else [] + ) + ++ ( + if selfConfig.synctex + then ["--synctex"] + else [] + ) + ++ ( + if selfConfig.untrustedInput + then ["--untrusted"] + else [] + ) + # Options + ++ ( + if selfConfig.reruns > 0 + then ["--reruns" "${toString selfConfig.reruns}"] + else [] + ) + ++ ( + if selfConfig.bundle != "" + then ["--bundle" "${toString selfConfig.bundle}"] + else [] + ) + ++ ( + if selfConfig.webBundle != "" + then ["--web-bundle" "${toString selfConfig.webBundle}"] + else [] + ) + ++ ( + if selfConfig.outfmt != "" + then ["--outfmt" "${toString selfConfig.outfmt}"] + else [] + ) + ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) + ++ ( + if selfConfig.format != "" + then ["--format" "${toString selfConfig.format}"] + else [] + ) + ++ ( + if selfConfig.color != "" + then ["--color" "${toString selfConfig.color}"] + else [] + ) + # 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 buildConfig.pdfDirectory ["." ""]) + then ["--outdir" "${buildConfig.pdfDirectory}"] + else [] + ) + ); +in { + options.vim.languages.tex.build.builders.tectonic = { + enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; + + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; + }; + + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # -- Flags -- + keepIntermediates = mkEnableDefaultOption false '' + Keep the intermediate files generated during processing. + + If texlab is reporting build errors when there shouldn't be, disable this option. + ''; + keepLogs = mkEnableDefaultOption true '' + Keep the log files generated during processing. + + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; + synctex = mkEnableDefaultOption true "Generate SyncTeX data"; + untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = "Rerun the TeX engine exactly this many times after the first"; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; + }; + + config = mkIf (cfg.enable && cfg.build.builders.tectonic.enable) { + vim.languages.tex.build.builder = { + name = "tectonic"; + args = collateArgs cfg.build; + package = cfg.build.builders.tectonic.package; + executable = cfg.build.builders.tectonic.executable; + }; + }; +} From aa75d98822d2594dbc7a26b81ce2618af9674a2f Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Fri, 24 Jan 2025 10:49:26 -0700 Subject: [PATCH 21/65] Created latexmk builder --- .../tex/build/builders/builderTemplate.nix | 19 +++--- .../languages/tex/build/builders/default.nix | 2 +- .../languages/tex/build/builders/latexmk.nix | 68 +++++++++++++++++++ 3 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 modules/plugins/languages/tex/build/builders/latexmk.nix diff --git a/modules/plugins/languages/tex/build/builders/builderTemplate.nix b/modules/plugins/languages/tex/build/builders/builderTemplate.nix index 3d3f607f..c9cc8163 100644 --- a/modules/plugins/languages/tex/build/builders/builderTemplate.nix +++ b/modules/plugins/languages/tex/build/builders/builderTemplate.nix @@ -1,36 +1,35 @@ # This function acts as a template for creating new builders. # It enforces providing all the parameters required for creating # a new builder for it to be able to work in the existing code. - +# # The first layer requirements are as follows: { # This is the name of the builder, it will only be used internally and # should match the .nix file that the builder is implemented in. name, - + # # Module attribute set. This is the attribute set that the module that is # defining a builder is passed as its input. moduleInheritencePackage, - + # # These are the standard options for the builder just like creating any # other module. Some options are required and are described below but # it will also accept any other options that are provided to it. options, - + # # These are the command line arguments that will accompany the executable # when the build command is called. # This is a function that will take in the cfg of its own builder. # i.e. will be called as "args cfg.build.builders.${name}" args, - ... }: let # Inherit the necessary variables available to any module. inherit (moduleInheritencePackage) lib config; - + # # Inherit other useful functions. inherit (lib.modules) mkIf; - + # # Set the cfg variable cfg = config.vim.languages.tex; in { @@ -39,15 +38,15 @@ in { options.vim.languages.tex.build.builders.${name} = ({ # The enable option. This one is self explanatory. enable, - + # # This is the package option for the builder. package, - + # # This is the executable that will be used to call the builder. # It, along with package will result in: # "/bin/" executable, - + # # Any other options provided are accepted. ... } @ opts: diff --git a/modules/plugins/languages/tex/build/builders/default.nix b/modules/plugins/languages/tex/build/builders/default.nix index 3e9eca59..0e4eb8d8 100644 --- a/modules/plugins/languages/tex/build/builders/default.nix +++ b/modules/plugins/languages/tex/build/builders/default.nix @@ -13,7 +13,7 @@ let in { imports = [ - # ./custom.nix + ./latexmk.nix ./tectonic.nix ]; diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix new file mode 100644 index 00000000..1cc4eb51 --- /dev/null +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -0,0 +1,68 @@ +# TODO: I need testing. +{ + config, + pkgs, + lib, + ... +} @ moduleInheritencePackage: let + # The name of the builder + name = "latexmk"; + + # The builder template + template = import ./builderTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) bool package str; + + cfg = config.vim.languages.tex; + + # --- Enable Options --- + mkEnableDefaultOption = default: description: (mkOption { + type = bool; + default = default; + example = !default; + description = description; + }); +in ( + template { + inherit name moduleInheritencePackage; + + options = { + enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk"; + + package = mkOption { + type = package; + default = (pkgs.texlive.withPackages (ps: [ ps.latexmk ])); + description = "latexmk package"; + }; + + executable = mkOption { + type = str; + default = "latexmk"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # Flag options + pdfOutput = mkOption { + type = bool; + default = true; + example = false; + description = "Insure the output file is a pdf."; + }; + }; + + args = builderCfg: ( + # Flags + ( + if builderCfg.pdfOutput + then ["-pdf"] + else [] + ) + # Base args + ++ [ + "-quiet" + "%f" + ] + ); + } +) From a2ffaf84ac0031ea41f6ca06975c29e3212d7615 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 16:06:21 -0700 Subject: [PATCH 23/65] Switched to using lib.nvim.config.mkBool where appropriate --- .../languages/tex/build/builders/latexmk.nix | 11 -------- .../languages/tex/build/builders/tectonic.nix | 27 +++++++++---------- modules/plugins/languages/tex/lsp/texlab.nix | 25 +++-------------- 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index 1cc4eb51..edc46584 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -1,6 +1,5 @@ # TODO: I need testing. { - config, pkgs, lib, ... @@ -13,16 +12,6 @@ inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) bool package str; - - cfg = config.vim.languages.tex; - - # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); in ( template { inherit name moduleInheritencePackage; diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 71facf1e..ec6e253c 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -11,18 +11,11 @@ template = import ./builderTemplate.nix; inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) bool enum ints listOf package str; + inherit (lib.types) enum ints listOf package str; + inherit (lib.nvim.config) mkBool; inherit (builtins) concatLists elem map toString; cfg = config.vim.languages.tex; - - # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); in ( template { inherit name moduleInheritencePackage; @@ -43,26 +36,30 @@ in ( }; # -- Flags -- - keepIntermediates = mkEnableDefaultOption false '' + keepIntermediates = mkBool false '' Keep the intermediate files generated during processing. If texlab is reporting build errors when there shouldn't be, disable this option. ''; - keepLogs = mkEnableDefaultOption true '' + keepLogs = mkBool true '' Keep the log files generated during processing. Without the keepLogs flag, texlab won't be able to report compilation warnings. ''; - onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; + onlyCached = mkBool false "Use only resource files cached locally"; + synctex = mkBool true "Generate SyncTeX data"; + untrustedInput = mkBool false "Input is untrusted -- disable all known-insecure features"; # -- Options -- reruns = mkOption { type = ints.unsigned; default = 0; example = 2; - description = "Rerun the TeX engine exactly this many times after the first"; + description = '' + Rerun the TeX engine exactly this many times after the first. + + Setting this value to 0 will diable setting this option. + ''; }; bundle = mkOption { diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index fd319a6d..e5dea908 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -19,13 +19,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit - (lib.types) - bool - listOf - package - str - ; + inherit (lib.types) listOf package str; inherit (builtins) attrNames @@ -39,20 +33,14 @@ throw toString ; + inherit (lib.nvim.config) mkBool; cfg = config.vim.languages.tex; # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); - mkEnableLspOption = mkEnableDefaultOption config.vim.languages.enableLSP; in { options.vim.languages.tex.lsp.texlab = { - enable = mkEnableLspOption "Whether to enable Tex LSP support (texlab)"; + enable = mkBool config.vim.languages.enableLSP "Whether to enable Tex LSP support (texlab)"; package = mkOption { type = package; @@ -61,11 +49,7 @@ in { }; forwardSearch = { - enable = mkOption { - type = bool; - default = false; - example = true; - description = '' + enable = mkBool false '' Whether to enable forward search. Enable this option if you want to have the compiled document appear in your chosen PDF viewer. @@ -73,7 +57,6 @@ in { For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). Note this is not all the options, but can act as a guide to help you allong with custom configs. ''; - }; package = mkOption { type = package; default = pkgs.okular; From 8d7cac7e1c04eeb2f311cb3e5a0934dc55925188 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 18:42:54 -0700 Subject: [PATCH 24/65] Refactored to use the nvf library toLuaObject as well as other improvements and cleanups --- .../languages/tex/build/builders/default.nix | 14 +- .../plugins/languages/tex/build/default.nix | 80 ++++++--- modules/plugins/languages/tex/lsp/texlab.nix | 154 ++++++------------ 3 files changed, 119 insertions(+), 129 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/default.nix b/modules/plugins/languages/tex/build/builders/default.nix index 0e4eb8d8..4586b768 100644 --- a/modules/plugins/languages/tex/build/builders/default.nix +++ b/modules/plugins/languages/tex/build/builders/default.nix @@ -3,15 +3,14 @@ pkgs, lib, ... -}: -let +}: let inherit (lib.options) mkOption; inherit (lib.types) enum listOf package str; - inherit (builtins) attrNames; + inherit (lib.nvim.config) mkBool; + inherit (builtins) attrNames filter isAttrs hasAttr elemAt length; cfg = config.vim.languages.tex; -in -{ +in { imports = [ ./latexmk.nix ./tectonic.nix @@ -27,6 +26,8 @@ in This is just the default custom option. By setting any of the builders to true, this will be overwritten by that builder's parameters. + Setting this parameter to the name of a declared builder will + not automatically enable that builder. ''; }; args = mkOption { @@ -45,7 +46,7 @@ in }; package = mkOption { type = package; - default = (pkgs.texlive.withPackages (ps: [ ps.latexmk ])); + default = pkgs.texlive.withPackages (ps: [ps.latexmk]); description = '' The tex builder package to use. @@ -67,4 +68,3 @@ in }; }; } - diff --git a/modules/plugins/languages/tex/build/default.nix b/modules/plugins/languages/tex/build/default.nix index cbc9dca7..fe07775b 100644 --- a/modules/plugins/languages/tex/build/default.nix +++ b/modules/plugins/languages/tex/build/default.nix @@ -4,34 +4,71 @@ ... }: let inherit (lib.options) mkOption; - inherit (lib.types) bool str; + inherit (lib.types) str nullOr; + inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; + inherit (lib.nvim.config) mkBool; cfg = config.vim.languages.tex; + + enabledBuildersCount = let + # This function will sort through the builder options and count how many + # builders have been enabled. + getEnabledBuildersCount = { + enabledBuildersCount ? 0, + index ? 0, + builderNamesList ? ( + filter ( + x: let + y = cfg.build.builders.${x}; + in (isAttrs y && hasAttr "enable" y) + ) (attrNames cfg.build.builders) + ), + }: let + currentBuilderName = elemAt builderNamesList index; + currentBuilder = cfg.build.builders.${currentBuilderName}; + nextIndex = index + 1; + newEnabledBuildersCount = + if currentBuilder.enable + then enabledBuildersCount + 1 + else enabledBuildersCount; + in + if length builderNamesList > nextIndex + then + getEnabledBuildersCount { + inherit builderNamesList; + enabledBuildersCount = newEnabledBuildersCount; + index = nextIndex; + } + else newEnabledBuildersCount; + in (getEnabledBuildersCount {}); in { imports = [ ./builders ]; options.vim.languages.tex.build = { - forwardSearchAfter = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to execute a forward search after a build."; - }; - onSave = mkOption { - type = bool; - default = false; - description = "Set this property to true if you want to compile the project after saving a file."; - }; - useFileList = mkOption { - type = bool; - default = false; - description = '' - When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + enable = + mkBool ( + if enabledBuildersCount > 1 + then throw "nvf-tex-language does not support having more than 1 builders enabled!" + else (enabledBuildersCount == 1) + ) '' + Whether to enable configuring the builder. - Note that enabling this property might have an impact on performance. + By enabling any of the builders, this option will be automatically set. + If you enable more than one builder then an error will be thrown. ''; - }; + + forwardSearchAfter = mkBool false "Set this property to true if you want to execute a forward search after a build."; + + onSave = mkBool false "Set this property to true if you want to compile the project after saving a file."; + + useFileList = mkBool false '' + When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + + Note that enabling this property might have an impact on performance. + ''; + auxDirectory = mkOption { type = str; default = "."; @@ -42,6 +79,7 @@ in { When using a latexmkrc file, texlab will automatically infer the correct setting. ''; }; + logDirectory = mkOption { type = str; default = "."; @@ -52,6 +90,7 @@ in { When using a latexmkrc file, texlab will automatically infer the correct setting. ''; }; + pdfDirectory = mkOption { type = str; default = "."; @@ -62,9 +101,10 @@ in { When using a latexmkrc file, texlab will automatically infer the correct setting. ''; }; + filename = mkOption { - type = str; - default = ""; + 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. ''; diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index e5dea908..dcd05615 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -19,7 +19,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit (lib.types) listOf package str; + inherit (lib.types) listOf package str attrs; inherit (builtins) attrNames @@ -36,8 +36,8 @@ inherit (lib.nvim.config) mkBool; cfg = config.vim.languages.tex; - - # --- Enable Options --- + texlabCfg = cfg.lsp.texlab; + builderCfg = cfg.build.builder; in { options.vim.languages.tex.lsp.texlab = { enable = mkBool config.vim.languages.enableLSP "Whether to enable Tex LSP support (texlab)"; @@ -50,13 +50,13 @@ in { forwardSearch = { enable = mkBool false '' - Whether to enable forward search. + Whether to enable forward search. - Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + Enable this option if you want to have the compiled document appear in your chosen PDF viewer. - For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - Note this is not all the options, but can act as a guide to help you allong with custom configs. - ''; + For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + Note this is not all the options, but can act as a guide to help you allong with custom configs. + ''; package = mkOption { type = package; default = pkgs.okular; @@ -91,11 +91,11 @@ in { }; extraLuaSettings = mkOption { - type = str; - default = ""; - example = '' - formatterLineLength = 80, - ''; + type = attrs; + default = {}; + example = { + formatterLineLength = 80; + }; description = '' For any options that do not have options provided through nvf this can be used to add them. Options already declared in nvf config will NOT be overridden. @@ -119,97 +119,47 @@ in { config = mkIf (cfg.enable && (cfg.lsp.texlab.enable)) ( let - tl = cfg.lsp.texlab; - builder = cfg.build.builder; + # ----- Setup Config ----- + # Command to start the LSP + setupConfig.cmd = ["${texlabCfg.package}/bin/texlab"]; - listToLua = list: nullOnEmpty: - if length list == 0 - then - if nullOnEmpty - then "null" - else "{ }" - else "{ ${concatStringsSep ", " (map (x: ''"${toString x}"'') list)} }"; - - stringToLua = string: nullOnEmpty: - if string == "" - then - if nullOnEmpty - then "null" - else "" - else ''"${string}"''; - - boolToLua = boolean: - if boolean - then "true" - else "false"; - - # -- Build -- - buildConfig = let - # This function will sort through the builder options and count how many - # builders have been enabled. - getEnabledBuildersCount = { - enabledBuildersCount ? 0, - index ? 0, - builderNamesList ? ( - filter ( - x: let - y = cfg.build.builders.${x}; - in (isAttrs y && hasAttr "enable" y) - ) (attrNames cfg.build.builders) - ), - }: let - currentBuilderName = elemAt builderNamesList index; - currentBuilder = cfg.build.builders.${currentBuilderName}; - nextIndex = index + 1; - newEnabledBuildersCount = - if currentBuilder.enable - then enabledBuildersCount + 1 - else enabledBuildersCount; - in - if length builderNamesList > nextIndex - then - getEnabledBuildersCount { - inherit builderNamesList; - enabledBuildersCount = newEnabledBuildersCount; - index = nextIndex; - } - else newEnabledBuildersCount; - - enabledBuildersCount = getEnabledBuildersCount {}; - in - if enabledBuildersCount == 0 - then "" - else if enabledBuildersCount > 1 - then throw "Texlab does not support having more than 1 builders enabled!" - else '' - build = { - executable = "${builder.package}/bin/${builder.executable}", - args = ${listToLua builder.args false}, - forwardSearchAfter = ${boolToLua cfg.build.forwardSearchAfter}, - onSave = ${boolToLua cfg.build.onSave}, - useFileList = ${boolToLua cfg.build.useFileList}, - auxDirectory = ${stringToLua cfg.build.auxDirectory true}, - logDirectory = ${stringToLua cfg.build.logDirectory true}, - pdfDirectory = ${stringToLua cfg.build.pdfDirectory true}, - filename = ${stringToLua cfg.build.filename true}, - }, - ''; - in { - vim.lsp.lspconfig.sources.texlab = '' - lspconfig.texlab.setup { - cmd = { "${tl.package}/bin/texlab" }, - settings = { - texlab = { - ${buildConfig} - forwardSearch = { - executable = "${tl.forwardSearch.package}/bin/${tl.forwardSearch.executable}", - args = ${listToLua tl.forwardSearch.args true} - }, - ${tl.extraLuaSettings} - } + # Create texlab settings section + setupConfig.settings.texlab = ( + {} + # -- Forward Search -- + // ( + if texlabCfg.forwardSearch.enable + then { + forwardSearch = { + executable = "${texlabCfg.forwardSearch.package}/bin/${texlabCfg.forwardSearch.executable}"; + args = texlabCfg.forwardSearch.args; + }; } - } - ''; + else {} + ) + # -- Build -- + // ( + if cfg.build.enable + then { + build = { + executable = "${builderCfg.package}/bin/${builderCfg.executable}"; + args = builderCfg.args; + forwardSearchAfter = cfg.build.forwardSearchAfter; + onSave = cfg.build.onSave; + useFileList = cfg.build.useFileList; + auxDirectory = cfg.build.auxDirectory; + logDirectory = cfg.build.logDirectory; + pdfDirectory = cfg.build.pdfDirectory; + filename = cfg.build.filename; + }; + } + else {} + ) + # -- Extra -- + // texlabCfg.extraLuaSettings + ); + in { + vim.lsp.lspconfig.sources.texlab = "lspconfig.texlab.setup(${lib.nvim.lua.toLuaObject setupConfig})"; } ); } From 847c1b5647bbdbfa80c77ec10b1c74a26d32faca Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 18:56:41 -0700 Subject: [PATCH 25/65] Added diagnostic options for texlab --- modules/plugins/languages/tex/lsp/texlab.nix | 45 ++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index dcd05615..714ec46c 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -1,8 +1,6 @@ # TODO: # - Add Texlab LSP settings: # - chktex -# - diagnosticsDelay -# - diagnostics # - symbols # - formatterLineLength # - bibtexFormatter @@ -19,7 +17,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit (lib.types) listOf package str attrs; + inherit (lib.types) listOf package str attrs ints; inherit (builtins) attrNames @@ -90,6 +88,37 @@ in { }; }; + diagnostics = { + delay = mkOption { + type = ints.positive; + default = 300; + description = "Delay in milliseconds before reporting diagnostics."; + }; + allowedPatterns = mkOption { + type = listOf str; + default = []; + description = '' + A list of regular expressions used to filter the list of reported diagnostics. + If specified, only diagnostics that match at least one of the specified patterns are sent to the client. + + See also texlab.diagnostics.ignoredPatterns. + + Hint: If both allowedPatterns and ignoredPatterns are set, then allowed patterns are applied first. + Afterwards, the results are filtered with the ignored patterns. + ''; + }; + ignoredPatterns = mkOption { + type = listOf str; + default = []; + description = '' + A list of regular expressions used to filter the list of reported diagnostics. + If specified, only diagnostics that match none of the specified patterns are sent to the client. + + See also texlab.diagnostics.allowedPatterns. + ''; + }; + }; + extraLuaSettings = mkOption { type = attrs; default = {}; @@ -125,7 +154,15 @@ in { # Create texlab settings section setupConfig.settings.texlab = ( - {} + # -- General Settings -- + # -- Diagnostics -- + { + diagnosticsDelay = texlabCfg.diagnostics.delay; + diagnostics = { + allowedPatterns = texlabCfg.diagnostics.allowedPatterns; + ignoredPatterns = texlabCfg.diagnostics.ignoredPatterns; + }; + } # -- Forward Search -- // ( if texlabCfg.forwardSearch.enable From 39fd4fe6ff43aa3dfa2e742566dcc29135438390 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 19:09:35 -0700 Subject: [PATCH 26/65] Added general texlab options and some cleanup --- modules/plugins/languages/tex/lsp/texlab.nix | 53 +++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 714ec46c..37b06a08 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -2,9 +2,6 @@ # - Add Texlab LSP settings: # - chktex # - symbols -# - formatterLineLength -# - bibtexFormatter -# - latexFormatter # - latexindent # - completion # - inlayHints @@ -17,20 +14,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit (lib.types) listOf package str attrs ints; - inherit - (builtins) - attrNames - concatStringsSep - elemAt - filter - hasAttr - isAttrs - length - map - throw - toString - ; + inherit (lib.types) listOf package str attrs ints enum; inherit (lib.nvim.config) mkBool; cfg = config.vim.languages.tex; @@ -119,11 +103,37 @@ in { }; }; + formatterLineLength = mkOption { + type = ints.positive; + default = 80; + description = "Defines the maximum amount of characters per line (0 = disable) when formatting BibTeX files."; + }; + + bibtexFormatter = mkOption { + type = enum ["texlab" "latexindent"]; + default = "texlab"; + description = '' + Defines the formatter to use for BibTeX formatting. + Possible values are either texlab or latexindent. + ''; + }; + + latexFormatter = mkOption { + type = enum ["texlab" "latexindent"]; + default = "latexindent"; + description = '' + Defines the formatter to use for LaTeX formatting. + Possible values are either texlab or latexindent. + Note that texlab is not implemented yet. + ''; + }; + extraLuaSettings = mkOption { type = attrs; default = {}; example = { - formatterLineLength = 80; + foo = "bar"; + baz = 314; }; description = '' For any options that do not have options provided through nvf this can be used to add them. @@ -155,8 +165,13 @@ in { # Create texlab settings section setupConfig.settings.texlab = ( # -- General Settings -- - # -- Diagnostics -- { + formatterLineLength = texlabCfg.formatterLineLength; + bibtexFormatter = texlabCfg.bibtexFormatter; + latexFormatter = texlabCfg.latexFormatter; + } + # -- Diagnostics -- + // { diagnosticsDelay = texlabCfg.diagnostics.delay; diagnostics = { allowedPatterns = texlabCfg.diagnostics.allowedPatterns; From 179418e93631dfd2009f3b9474438493498d9fdc Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 19:26:06 -0700 Subject: [PATCH 27/65] Added latexindent options to texlab --- modules/plugins/languages/tex/lsp/texlab.nix | 39 +++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 37b06a08..2ed93229 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -2,7 +2,6 @@ # - Add Texlab LSP settings: # - chktex # - symbols -# - latexindent # - completion # - inlayHints # - experimental @@ -14,7 +13,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf; - inherit (lib.types) listOf package str attrs ints enum; + inherit (lib.types) listOf package str attrs ints enum either path nullOr; inherit (lib.nvim.config) mkBool; cfg = config.vim.languages.tex; @@ -103,6 +102,34 @@ in { }; }; + latexindent = { + local = mkOption { + type = nullOr (either str path); + default = null; + description = '' + Defines the path of a file containing the latexindent configuration. + This corresponds to the --local=file.yaml flag of latexindent. + By default the configuration inside the project root directory is used. + ''; + }; + modifyLineBreaks = mkBool false '' + Modifies linebreaks before, during, and at the end of code blocks when formatting with latexindent. + This corresponds to the --modifylinebreaks flag of latexindent. + ''; + replacement = mkOption { + type = nullOr (enum ["-r" "-rv" "-rr"]); + default = null; + description = '' + Defines an additional replacement flag that is added when calling latexindent. This can be one of the following: + - "-r" + - "-rv" + - "-rr" + - null + By default no replacement flag is passed. + ''; + }; + }; + formatterLineLength = mkOption { type = ints.positive; default = 80; @@ -178,6 +205,14 @@ in { ignoredPatterns = texlabCfg.diagnostics.ignoredPatterns; }; } + # -- Latex Indent -- + // { + latexindent = { + local = texlabCfg.latexindent.local; + modifyLineBreaks = texlabCfg.latexindent.modifyLineBreaks; + replacement = texlabCfg.latexindent.replacement; + }; + } # -- Forward Search -- // ( if texlabCfg.forwardSearch.enable From a5fb96675d763ef9db656da667ea1563bcd2341f Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 19:31:45 -0700 Subject: [PATCH 28/65] Added completion options for texlab --- modules/plugins/languages/tex/lsp/texlab.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 2ed93229..a0173efe 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -2,7 +2,6 @@ # - Add Texlab LSP settings: # - chktex # - symbols -# - completion # - inlayHints # - experimental { @@ -130,6 +129,18 @@ in { }; }; + completion.matcher = mkOption { + type = str; + default = "fuzzy-ignore-case"; + description = '' + Modifies the algorithm used to filter the completion items returned to the client. Possibles values are: + - fuzzy: Fuzzy string matching (case sensitive) + - fuzzy-ignore-case: Fuzzy string matching (case insensitive) + - prefix: Filter out items that do not start with the search text (case sensitive) + - prefix-ignore-case: Filter out items that do not start with the search text (case insensitive) + ''; + }; + formatterLineLength = mkOption { type = ints.positive; default = 80; @@ -213,6 +224,10 @@ in { replacement = texlabCfg.latexindent.replacement; }; } + # -- Completion -- + // { + completion.matcher = texlabCfg.completion.matcher; + } # -- Forward Search -- // ( if texlabCfg.forwardSearch.enable From 80938d1056327b317606c3715e0f4e90b0f4d325 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 19:47:50 -0700 Subject: [PATCH 29/65] Added inlayHints options for texlab and some cleanup --- modules/plugins/languages/tex/lsp/texlab.nix | 44 ++++++++++++-------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index a0173efe..0d192011 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -2,7 +2,6 @@ # - Add Texlab LSP settings: # - chktex # - symbols -# - inlayHints # - experimental { config, @@ -141,6 +140,16 @@ in { ''; }; + inlayHints = { + labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label-like` commands."; + labelReferences = mkBool true "When enabled, the server will return inlay hints for `\\ref``-like commands."; + maxLength = mkOption { + type = nullOr ints.positive; + default = null; + description = "When set, the server will truncate the text of the inlay hints to the specified length."; + }; + }; + formatterLineLength = mkOption { type = ints.positive; default = 80; @@ -202,32 +211,31 @@ in { # Create texlab settings section setupConfig.settings.texlab = ( - # -- General Settings -- { + # -- General Settings -- formatterLineLength = texlabCfg.formatterLineLength; + + # -- Formatters -- bibtexFormatter = texlabCfg.bibtexFormatter; latexFormatter = texlabCfg.latexFormatter; - } - # -- Diagnostics -- - // { + + # -- Diagnostics -- diagnosticsDelay = texlabCfg.diagnostics.delay; diagnostics = { allowedPatterns = texlabCfg.diagnostics.allowedPatterns; ignoredPatterns = texlabCfg.diagnostics.ignoredPatterns; }; - } - # -- Latex Indent -- - // { - latexindent = { - local = texlabCfg.latexindent.local; - modifyLineBreaks = texlabCfg.latexindent.modifyLineBreaks; - replacement = texlabCfg.latexindent.replacement; - }; - } - # -- Completion -- - // { + + # -- Latex Indent -- + latexindent = texlabCfg.latexindent; + + # -- Completion -- completion.matcher = texlabCfg.completion.matcher; + + # -- Inlay Hints -- + inlayHints = texlabCfg.inlayHints; } + # # -- Forward Search -- // ( if texlabCfg.forwardSearch.enable @@ -239,6 +247,7 @@ in { } else {} ) + # # -- Build -- // ( if cfg.build.enable @@ -257,7 +266,8 @@ in { } else {} ) - # -- Extra -- + # + # -- Extra Settings -- // texlabCfg.extraLuaSettings ); in { From 9300f920f61961cc3ad5752b13f4dbf7db294da8 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 20:05:48 -0700 Subject: [PATCH 30/65] Added experimental options for texlab --- modules/plugins/languages/tex/lsp/texlab.nix | 100 ++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 0d192011..2ce47dc7 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -2,7 +2,6 @@ # - Add Texlab LSP settings: # - chktex # - symbols -# - experimental { config, pkgs, @@ -36,6 +35,7 @@ in { For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). Note this is not all the options, but can act as a guide to help you allong with custom configs. ''; + package = mkOption { type = package; default = pkgs.okular; @@ -44,6 +44,7 @@ in { This viewer needs to support Synctex. ''; }; + executable = mkOption { type = str; default = "okular"; @@ -51,6 +52,7 @@ in { Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. ''; }; + args = mkOption { type = listOf str; default = [ @@ -75,6 +77,7 @@ in { default = 300; description = "Delay in milliseconds before reporting diagnostics."; }; + allowedPatterns = mkOption { type = listOf str; default = []; @@ -88,6 +91,7 @@ in { Afterwards, the results are filtered with the ignored patterns. ''; }; + ignoredPatterns = mkOption { type = listOf str; default = []; @@ -110,10 +114,12 @@ in { By default the configuration inside the project root directory is used. ''; }; + modifyLineBreaks = mkBool false '' Modifies linebreaks before, during, and at the end of code blocks when formatting with latexindent. This corresponds to the --modifylinebreaks flag of latexindent. ''; + replacement = mkOption { type = nullOr (enum ["-r" "-rv" "-rr"]); default = null; @@ -142,7 +148,9 @@ in { inlayHints = { labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label-like` commands."; + labelReferences = mkBool true "When enabled, the server will return inlay hints for `\\ref``-like commands."; + maxLength = mkOption { type = nullOr ints.positive; default = null; @@ -150,6 +158,93 @@ in { }; }; + experimental = { + followPackageLinks = mkBool false "If set to true, dependencies of custom packages are resolved and included in the dependency graph."; + + mathEnvironments = mkOption { + type = listOf str; + default = []; + description = "Allows extending the list of environments which the server considers as math environments (for example `align*` or `equation`)."; + }; + + enumEnvironments = mkOption { + type = listOf str; + default = []; + description = "Allows extending the list of environments which the server considers as enumeration environments (for example `enumerate` or `itemize`)."; + }; + + verbatimEnvironments = mkOption { + type = listOf str; + default = []; + description = '' + Allows extending the list of environments which the server considers as verbatim environments (for example `minted` or `lstlisting`). + This can be used to suppress diagnostics from environments that do not contain LaTeX code. + ''; + }; + + citationCommands = mkOption { + type = listOf str; + default = []; + description = '' + Allows extending the list of commands which the server considers as citation commands (for example `\cite`). + + Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + ''; + }; + labelDefinitionCommands = mkOption { + type = listOf str; + default = []; + description = '' + Allows extending the list of `\label`-like commands. + + Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + ''; + }; + + labelReferenceCommands = mkOption { + type = listOf str; + default = []; + description = '' + Allows extending the list of `\ref`-like commands. + + Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + ''; + }; + + labelReferenceRangeCommands = mkOption { + type = listOf str; + default = []; + description = '' + Allows extending the list of `\crefrange`-like commands. + + Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + ''; + }; + + labelDefinitionPrefixes = mkOption { + type = listOf (listOf str); + default = []; + description = '' + Allows associating a label definition command with a custom prefix. Consider, + ``` + \newcommand{\thm}[1]{\label{thm:#1}} + \thm{foo} + ``` + Then setting `texlab.experimental.labelDefinitionPrefixes` to `[["thm", "thm:"]]` and adding "thm" + to `texlab.experimental.labelDefinitionCommands` will make the server recognize the `thm:foo` label. + ''; + }; + + labelReferencePrefixes = mkOption { + type = listOf (listOf str); + default = []; + description = '' + Allows associating a label reference command with a custom prefix. + See `texlab.experimental.labelDefinitionPrefixes` for more details. + ''; + }; + }; + formatterLineLength = mkOption { type = ints.positive; default = 80; @@ -234,6 +329,9 @@ in { # -- Inlay Hints -- inlayHints = texlabCfg.inlayHints; + + # -- Experimental -- + experimental = texlabCfg.experimental; } # # -- Forward Search -- From d7de68f37ea88bd2fa830810ce48c84bfd77d8f2 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 26 Jan 2025 20:11:20 -0700 Subject: [PATCH 31/65] Removed old files --- .../tex/build/builders/custom.nix.bak | 66 ------ .../tex/build/builders/tectonic.nix.bak | 217 ------------------ 2 files changed, 283 deletions(-) delete mode 100644 modules/plugins/languages/tex/build/builders/custom.nix.bak delete mode 100644 modules/plugins/languages/tex/build/builders/tectonic.nix.bak diff --git a/modules/plugins/languages/tex/build/builders/custom.nix.bak b/modules/plugins/languages/tex/build/builders/custom.nix.bak deleted file mode 100644 index 01b5913c..00000000 --- a/modules/plugins/languages/tex/build/builders/custom.nix.bak +++ /dev/null @@ -1,66 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: let - inherit (lib.options) mkOption; - inherit (lib.modules) mkIf; - inherit (lib.types) bool listOf package str; - inherit (lib) mkDefault; - - cfg = config.vim.languages.tex; - - # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); - - collateArgs = buildConfig: buildConfig.builders.custom.args; -in { - options.vim.languages.tex.build.builders.custom = { - enable = mkEnableDefaultOption false "Whether to enable using a custom build package"; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "build/compiler package"; - }; - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - args = mkOption { - type = listOf str; - default = [ - "-X" - "compile" - "%f" - "--synctex" - "--keep-logs" - "--keep-intermediates" - ]; - description = '' - Defines additional arguments that are passed to the configured LaTeX build tool. - Note that flags and their arguments need to be separate elements in this array. - To pass the arguments -foo bar to a build tool, args needs to be ["-foo" "bar"]. - The placeholder `%f` will be replaced by the server. - - Placeholders: - - `%f`: The path of the TeX file to compile. - ''; - }; - }; - - config = mkIf (cfg.enable && cfg.build.builders.custom.enable) { - vim.languages.tex.build.builder = { - name = mkDefault "custom"; - args = mkDefault (collateArgs cfg.build); - package = mkDefault (cfg.build.builders.custom.package); - executable = mkDefault (cfg.build.builders.custom.executable); - }; - }; -} diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix.bak b/modules/plugins/languages/tex/build/builders/tectonic.nix.bak deleted file mode 100644 index 82f4b8b2..00000000 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix.bak +++ /dev/null @@ -1,217 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: let - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.modules) mkIf; - inherit - (lib.types) - bool - enum - ints - listOf - package - str - ; - inherit (builtins) concatLists elem map toString; - - cfg = config.vim.languages.tex; - - # --- Enable Options --- - mkEnableDefaultOption = default: description: (mkOption { - type = bool; - default = default; - example = !default; - description = description; - }); - - # --- Arg Collation Functions -- - collateArgs = buildConfig: let - selfConfig = buildConfig.builders.tectonic; - in ( - # Base args - [ - "-X" - "compile" - "%f" - ] - # Flags - ++ ( - if selfConfig.keepIntermediates - then ["--keep-intermediates"] - else [] - ) - ++ ( - if selfConfig.keepLogs - then ["--keep-logs"] - else [] - ) - ++ ( - if selfConfig.onlyCached - then ["--only-cached"] - else [] - ) - ++ ( - if selfConfig.synctex - then ["--synctex"] - else [] - ) - ++ ( - if selfConfig.untrustedInput - then ["--untrusted"] - else [] - ) - # Options - ++ ( - if selfConfig.reruns > 0 - then ["--reruns" "${toString selfConfig.reruns}"] - else [] - ) - ++ ( - if selfConfig.bundle != "" - then ["--bundle" "${toString selfConfig.bundle}"] - else [] - ) - ++ ( - if selfConfig.webBundle != "" - then ["--web-bundle" "${toString selfConfig.webBundle}"] - else [] - ) - ++ ( - if selfConfig.outfmt != "" - then ["--outfmt" "${toString selfConfig.outfmt}"] - else [] - ) - ++ (concatLists (map (x: ["--hide" x]) selfConfig.hidePaths)) - ++ ( - if selfConfig.format != "" - then ["--format" "${toString selfConfig.format}"] - else [] - ) - ++ ( - if selfConfig.color != "" - then ["--color" "${toString selfConfig.color}"] - else [] - ) - # 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 buildConfig.pdfDirectory ["." ""]) - then ["--outdir" "${buildConfig.pdfDirectory}"] - else [] - ) - ); -in { - options.vim.languages.tex.build.builders.tectonic = { - enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; - - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; - - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - - # -- Flags -- - keepIntermediates = mkEnableDefaultOption false '' - Keep the intermediate files generated during processing. - - If texlab is reporting build errors when there shouldn't be, disable this option. - ''; - keepLogs = mkEnableDefaultOption true '' - Keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation warnings. - ''; - onlyCached = mkEnableDefaultOption false "Use only resource files cached locally"; - synctex = mkEnableDefaultOption true "Generate SyncTeX data"; - untrustedInput = mkEnableDefaultOption false "Input is untrusted -- disable all known-insecure features"; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = "Rerun the TeX engine exactly this many times after the first"; - }; - - bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - }; - - webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; - }; - - outfmt = mkOption { - type = enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = "Tell the engine that no file at exists, if it tries to read it."; - }; - - format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; - }; - - color = mkOption { - type = enum [ - "always" - "auto" - "never" - "" - ]; - default = ""; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. - ''; - }; - }; - - config = mkIf (cfg.enable && cfg.build.builders.tectonic.enable) { - vim.languages.tex.build.builder = { - name = "tectonic"; - args = collateArgs cfg.build; - package = cfg.build.builders.tectonic.package; - executable = cfg.build.builders.tectonic.executable; - }; - }; -} From 06fbacb3d065970e7907b128affaade85d9badf0 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 12:25:19 -0700 Subject: [PATCH 32/65] Added enum options for completion matcher option --- modules/plugins/languages/tex/lsp/texlab.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 2ce47dc7..c05dcfaa 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -135,7 +135,7 @@ in { }; completion.matcher = mkOption { - type = str; + type = enum ["fuzzy" "fuzzy-ignore-case" "prefix" "prefix-ignore-case"]; default = "fuzzy-ignore-case"; description = '' Modifies the algorithm used to filter the completion items returned to the client. Possibles values are: From b4098ad71f5b5a9142c10da481c4d672a63ce463 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 13:03:48 -0700 Subject: [PATCH 33/65] Added chktex options for texlab --- modules/plugins/languages/tex/lsp/texlab.nix | 54 +++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index c05dcfaa..cde4ed17 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -1,6 +1,5 @@ # TODO: # - Add Texlab LSP settings: -# - chktex # - symbols { config, @@ -9,7 +8,7 @@ ... }: let inherit (lib.options) mkOption; - inherit (lib.modules) mkIf; + inherit (lib.modules) mkIf mkMerge; inherit (lib.types) listOf package str attrs ints enum either path nullOr; inherit (lib.nvim.config) mkBool; @@ -104,6 +103,32 @@ in { }; }; + chktex = { + enable = mkBool false "Whether to enable linting via chktex"; + + package = mkOption { + type = package; + default = pkgs.texlive.withPackages (ps: [ps.chktex]); + description = '' + The chktex package to use. + Must have the `chktex` executable. + ''; + }; + + onOpenAndSave = mkBool false "Lint using chktex after opening and saving a file."; + + onEdit = mkBool false "Lint using chktex after editing a file."; + + additionalArgs = mkOption { + type = listOf str; + default = []; + description = '' + Additional command line arguments that are passed to chktex after editing a file. + Don't redefine the `-I` and `-f` flags as they are set by the server. + ''; + }; + }; + latexindent = { local = mkOption { type = nullOr (either str path); @@ -298,7 +323,7 @@ in { }; }; - config = mkIf (cfg.enable && (cfg.lsp.texlab.enable)) ( + config = mkIf cfg.enable ( let # ----- Setup Config ----- # Command to start the LSP @@ -346,6 +371,17 @@ in { else {} ) # + # -- Chktex -- + // ( + if texlabCfg.chktex.enable + then { + chktex = { + inherit (texlabCfg.chktex) onOpenAndSave onEdit additionalArgs; + }; + } + else {} + ) + # # -- Build -- // ( if cfg.build.enable @@ -368,8 +404,14 @@ in { # -- Extra Settings -- // texlabCfg.extraLuaSettings ); - in { - vim.lsp.lspconfig.sources.texlab = "lspconfig.texlab.setup(${lib.nvim.lua.toLuaObject setupConfig})"; - } + in (mkMerge [ + (mkIf texlabCfg.enable { + vim.lsp.lspconfig.sources.texlab = "lspconfig.texlab.setup(${lib.nvim.lua.toLuaObject setupConfig})"; + }) + + (mkIf texlabCfg.chktex.enable { + vim.extraPackages = [texlabCfg.chktex.package]; + }) + ]) ); } From 0c3c67d068fd76c049b0dc9bb61e70706f10a4db Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 13:56:38 -0700 Subject: [PATCH 34/65] Added symbol options for texlab --- modules/plugins/languages/tex/lsp/texlab.nix | 107 ++++++++++++++++++- 1 file changed, 103 insertions(+), 4 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index cde4ed17..bf7d61dc 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -1,6 +1,3 @@ -# TODO: -# - Add Texlab LSP settings: -# - symbols { config, pkgs, @@ -9,8 +6,9 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) listOf package str attrs ints enum either path nullOr; + inherit (lib.types) listOf package str attrs ints enum either path nullOr submodule; inherit (lib.nvim.config) mkBool; + inherit (builtins) isString map; cfg = config.vim.languages.tex; texlabCfg = cfg.lsp.texlab; @@ -129,6 +127,86 @@ in { }; }; + symbols = { + enable = mkBool false "Whether to enable setting symbols config."; + + allowedPatterns = mkOption { + type = listOf str; + default = []; + description = '' + A list of regular expressions used to filter the list of reported document symbols. + If specified, only symbols that match at least one of the specified patterns are sent to the client. + Symbols are filtered recursively so nested symbols can still be sent to the client even though the + parent node is removed from the results. + + See also `texlab.symbols.ignoredPatterns`. + + Hint: If both allowedPatterns and ignoredPatterns are set, then allowed patterns are applied first. + Afterwards, the results are filtered with the ignored patterns. + ''; + }; + + ignoredPatterns = mkOption { + type = listOf str; + default = []; + description = '' + A list of regular expressions used to filter the list of reported document symbols. + If specified, only symbols that match none of the specified patterns are sent to the client. + + See also `texlab.symbols.allowedPatterns`. + ''; + }; + + customEnvironments = mkOption { + type = listOf (submodule { + options = { + name = mkOption { + type = str; + description = "The name of the environment."; + }; + displayName = mkOption { + type = nullOr str; + default = null; + description = "The name shown in the document symbols. Defaults to the value of `name`."; + }; + label = mkBool false '' + If set, the server will try to match a label to environment and append its number. + ''; + }; + }); + default = []; + example = [ + { + name = "foo"; + displayName = "bar"; + label = false; + } + ]; + description = '' + A list of objects that allows extending the list of environments that are part of the document symbols. + + See also texlab.symbols.allowedPatterns. + + Type: listOf submodule: + - name: + - type: str + - description: The name of the environment. + - required + - displayName: + - type: nullOr str + - description: The name shown in the document symbols. + - default: + - label: + - type: boolean + - description: If set, the server will try to match a label to environment and append its number. + - default: false + + Note: This functionallity may not be working, please follow https://github.com/latex-lsp/texlab/pull/1311 + for status updates. + ''; + }; + }; + latexindent = { local = mkOption { type = nullOr (either str path); @@ -382,6 +460,27 @@ in { else {} ) # + # -- Symbols -- + // ( + if texlabCfg.symbols.enable + then { + symbols = { + inherit (texlabCfg.symbols) allowedPatterns ignoredPatterns; + + customEnvironments = + map (x: { + inherit (x) name label; + displayName = + if isString x.displayName + then x.displayName + else x.name; + }) + texlabCfg.symbols.customEnvironments; + }; + } + else {} + ) + # # -- Build -- // ( if cfg.build.enable From 35430ca7ab03f783cb4cf852950d000a631b0482 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 14:37:30 -0700 Subject: [PATCH 35/65] Cleanup: Sorted sections alphabetically, utilized inherrits where appropriate --- modules/plugins/languages/tex/lsp/texlab.nix | 508 +++++++++---------- 1 file changed, 254 insertions(+), 254 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index bf7d61dc..fca7c759 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -23,51 +23,44 @@ in { description = "texlab package"; }; - forwardSearch = { - enable = mkBool false '' - Whether to enable forward search. - - Enable this option if you want to have the compiled document appear in your chosen PDF viewer. - - For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - Note this is not all the options, but can act as a guide to help you allong with custom configs. - ''; + chktex = { + enable = mkBool false "Whether to enable linting via chktex"; package = mkOption { type = package; - default = pkgs.okular; + default = pkgs.texlive.withPackages (ps: [ps.chktex]); description = '' - The package to use as your PDF viewer. - This viewer needs to support Synctex. + The chktex package to use. + Must have the `chktex` executable. ''; }; - executable = mkOption { - type = str; - default = "okular"; - description = '' - Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. - ''; - }; + onOpenAndSave = mkBool false "Lint using chktex after opening and saving a file."; - args = mkOption { + onEdit = mkBool false "Lint using chktex after editing a file."; + + additionalArgs = mkOption { type = listOf str; - default = [ - "--unique" - "file:%p#src:%l%f" - ]; + default = []; description = '' - Defines additional arguments that are passed to the configured previewer to perform the forward search. - The placeholders %f, %p, %l will be replaced by the server. - - Placeholders: - - %f: The path of the current TeX file. - - %p: The path of the current PDF file. - - %l: The current line number. + Additional command line arguments that are passed to chktex after editing a file. + Don't redefine the `-I` and `-f` flags as they are set by the server. ''; }; }; + completion.matcher = mkOption { + type = enum ["fuzzy" "fuzzy-ignore-case" "prefix" "prefix-ignore-case"]; + default = "fuzzy-ignore-case"; + description = '' + Modifies the algorithm used to filter the completion items returned to the client. Possibles values are: + - fuzzy: Fuzzy string matching (case sensitive) + - fuzzy-ignore-case: Fuzzy string matching (case insensitive) + - prefix: Filter out items that do not start with the search text (case sensitive) + - prefix-ignore-case: Filter out items that do not start with the search text (case insensitive) + ''; + }; + diagnostics = { delay = mkOption { type = ints.positive; @@ -101,166 +94,6 @@ in { }; }; - chktex = { - enable = mkBool false "Whether to enable linting via chktex"; - - package = mkOption { - type = package; - default = pkgs.texlive.withPackages (ps: [ps.chktex]); - description = '' - The chktex package to use. - Must have the `chktex` executable. - ''; - }; - - onOpenAndSave = mkBool false "Lint using chktex after opening and saving a file."; - - onEdit = mkBool false "Lint using chktex after editing a file."; - - additionalArgs = mkOption { - type = listOf str; - default = []; - description = '' - Additional command line arguments that are passed to chktex after editing a file. - Don't redefine the `-I` and `-f` flags as they are set by the server. - ''; - }; - }; - - symbols = { - enable = mkBool false "Whether to enable setting symbols config."; - - allowedPatterns = mkOption { - type = listOf str; - default = []; - description = '' - A list of regular expressions used to filter the list of reported document symbols. - If specified, only symbols that match at least one of the specified patterns are sent to the client. - Symbols are filtered recursively so nested symbols can still be sent to the client even though the - parent node is removed from the results. - - See also `texlab.symbols.ignoredPatterns`. - - Hint: If both allowedPatterns and ignoredPatterns are set, then allowed patterns are applied first. - Afterwards, the results are filtered with the ignored patterns. - ''; - }; - - ignoredPatterns = mkOption { - type = listOf str; - default = []; - description = '' - A list of regular expressions used to filter the list of reported document symbols. - If specified, only symbols that match none of the specified patterns are sent to the client. - - See also `texlab.symbols.allowedPatterns`. - ''; - }; - - customEnvironments = mkOption { - type = listOf (submodule { - options = { - name = mkOption { - type = str; - description = "The name of the environment."; - }; - displayName = mkOption { - type = nullOr str; - default = null; - description = "The name shown in the document symbols. Defaults to the value of `name`."; - }; - label = mkBool false '' - If set, the server will try to match a label to environment and append its number. - ''; - }; - }); - default = []; - example = [ - { - name = "foo"; - displayName = "bar"; - label = false; - } - ]; - description = '' - A list of objects that allows extending the list of environments that are part of the document symbols. - - See also texlab.symbols.allowedPatterns. - - Type: listOf submodule: - - name: - - type: str - - description: The name of the environment. - - required - - displayName: - - type: nullOr str - - description: The name shown in the document symbols. - - default: - - label: - - type: boolean - - description: If set, the server will try to match a label to environment and append its number. - - default: false - - Note: This functionallity may not be working, please follow https://github.com/latex-lsp/texlab/pull/1311 - for status updates. - ''; - }; - }; - - latexindent = { - local = mkOption { - type = nullOr (either str path); - default = null; - description = '' - Defines the path of a file containing the latexindent configuration. - This corresponds to the --local=file.yaml flag of latexindent. - By default the configuration inside the project root directory is used. - ''; - }; - - modifyLineBreaks = mkBool false '' - Modifies linebreaks before, during, and at the end of code blocks when formatting with latexindent. - This corresponds to the --modifylinebreaks flag of latexindent. - ''; - - replacement = mkOption { - type = nullOr (enum ["-r" "-rv" "-rr"]); - default = null; - description = '' - Defines an additional replacement flag that is added when calling latexindent. This can be one of the following: - - "-r" - - "-rv" - - "-rr" - - null - By default no replacement flag is passed. - ''; - }; - }; - - completion.matcher = mkOption { - type = enum ["fuzzy" "fuzzy-ignore-case" "prefix" "prefix-ignore-case"]; - default = "fuzzy-ignore-case"; - description = '' - Modifies the algorithm used to filter the completion items returned to the client. Possibles values are: - - fuzzy: Fuzzy string matching (case sensitive) - - fuzzy-ignore-case: Fuzzy string matching (case insensitive) - - prefix: Filter out items that do not start with the search text (case sensitive) - - prefix-ignore-case: Filter out items that do not start with the search text (case insensitive) - ''; - }; - - inlayHints = { - labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label-like` commands."; - - labelReferences = mkBool true "When enabled, the server will return inlay hints for `\\ref``-like commands."; - - maxLength = mkOption { - type = nullOr ints.positive; - default = null; - description = "When set, the server will truncate the text of the inlay hints to the specified length."; - }; - }; - experimental = { followPackageLinks = mkBool false "If set to true, dependencies of custom packages are resolved and included in the dependency graph."; @@ -348,31 +181,6 @@ in { }; }; - formatterLineLength = mkOption { - type = ints.positive; - default = 80; - description = "Defines the maximum amount of characters per line (0 = disable) when formatting BibTeX files."; - }; - - bibtexFormatter = mkOption { - type = enum ["texlab" "latexindent"]; - default = "texlab"; - description = '' - Defines the formatter to use for BibTeX formatting. - Possible values are either texlab or latexindent. - ''; - }; - - latexFormatter = mkOption { - type = enum ["texlab" "latexindent"]; - default = "latexindent"; - description = '' - Defines the formatter to use for LaTeX formatting. - Possible values are either texlab or latexindent. - Note that texlab is not implemented yet. - ''; - }; - extraLuaSettings = mkOption { type = attrs; default = {}; @@ -399,6 +207,200 @@ in { ``` ''; }; + + forwardSearch = { + enable = mkBool false '' + Whether to enable forward search. + + Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + + For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). + Note this is not all the options, but can act as a guide to help you allong with custom configs. + ''; + + package = mkOption { + type = package; + default = pkgs.okular; + description = '' + The package to use as your PDF viewer. + This viewer needs to support Synctex. + ''; + }; + + executable = mkOption { + type = str; + default = "okular"; + description = '' + Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + ''; + }; + + args = mkOption { + type = listOf str; + default = [ + "--unique" + "file:%p#src:%l%f" + ]; + description = '' + Defines additional arguments that are passed to the configured previewer to perform the forward search. + The placeholders %f, %p, %l will be replaced by the server. + + Placeholders: + - %f: The path of the current TeX file. + - %p: The path of the current PDF file. + - %l: The current line number. + ''; + }; + }; + + formatter = { + formatterLineLength = mkOption { + type = ints.positive; + default = 80; + description = "Defines the maximum amount of characters per line (0 = disable) when formatting BibTeX files."; + }; + + bibtexFormatter = mkOption { + type = enum ["texlab" "latexindent"]; + default = "texlab"; + description = '' + Defines the formatter to use for BibTeX formatting. + Possible values are either texlab or latexindent. + ''; + }; + + latexFormatter = mkOption { + type = enum ["texlab" "latexindent"]; + default = "latexindent"; + description = '' + Defines the formatter to use for LaTeX formatting. + Possible values are either texlab or latexindent. + Note that texlab is not implemented yet. + ''; + }; + }; + + inlayHints = { + labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label-like` commands."; + + labelReferences = mkBool true "When enabled, the server will return inlay hints for `\\ref``-like commands."; + + maxLength = mkOption { + type = nullOr ints.positive; + default = null; + description = "When set, the server will truncate the text of the inlay hints to the specified length."; + }; + }; + + latexindent = { + local = mkOption { + type = nullOr (either str path); + default = null; + description = '' + Defines the path of a file containing the latexindent configuration. + This corresponds to the --local=file.yaml flag of latexindent. + By default the configuration inside the project root directory is used. + ''; + }; + + modifyLineBreaks = mkBool false '' + Modifies linebreaks before, during, and at the end of code blocks when formatting with latexindent. + This corresponds to the --modifylinebreaks flag of latexindent. + ''; + + replacement = mkOption { + type = nullOr (enum ["-r" "-rv" "-rr"]); + default = null; + description = '' + Defines an additional replacement flag that is added when calling latexindent. This can be one of the following: + - "-r" + - "-rv" + - "-rr" + - null + By default no replacement flag is passed. + ''; + }; + }; + + symbols = { + enable = mkBool false "Whether to enable setting symbols config."; + + allowedPatterns = mkOption { + type = listOf str; + default = []; + description = '' + A list of regular expressions used to filter the list of reported document symbols. + If specified, only symbols that match at least one of the specified patterns are sent to the client. + Symbols are filtered recursively so nested symbols can still be sent to the client even though the + parent node is removed from the results. + + See also `texlab.symbols.ignoredPatterns`. + + Hint: If both allowedPatterns and ignoredPatterns are set, then allowed patterns are applied first. + Afterwards, the results are filtered with the ignored patterns. + ''; + }; + + ignoredPatterns = mkOption { + type = listOf str; + default = []; + description = '' + A list of regular expressions used to filter the list of reported document symbols. + If specified, only symbols that match none of the specified patterns are sent to the client. + + See also `texlab.symbols.allowedPatterns`. + ''; + }; + + customEnvironments = mkOption { + type = listOf (submodule { + options = { + name = mkOption { + type = str; + description = "The name of the environment."; + }; + displayName = mkOption { + type = nullOr str; + default = null; + description = "The name shown in the document symbols. Defaults to the value of `name`."; + }; + label = mkBool false '' + If set, the server will try to match a label to environment and append its number. + ''; + }; + }); + default = []; + example = [ + { + name = "foo"; + displayName = "bar"; + label = false; + } + ]; + description = '' + A list of objects that allows extending the list of environments that are part of the document symbols. + + See also texlab.symbols.allowedPatterns. + + Type: listOf submodule: + - name: + - type: str + - description: The name of the environment. + - required + - displayName: + - type: nullOr str + - description: The name shown in the document symbols. + - default: + - label: + - type: boolean + - description: If set, the server will try to match a label to environment and append its number. + - default: false + + Note: This functionallity may not be working, please follow https://github.com/latex-lsp/texlab/pull/1311 + for status updates. + ''; + }; + }; }; config = mkIf cfg.enable ( @@ -410,40 +412,45 @@ in { # Create texlab settings section setupConfig.settings.texlab = ( { - # -- General Settings -- - formatterLineLength = texlabCfg.formatterLineLength; - - # -- Formatters -- - bibtexFormatter = texlabCfg.bibtexFormatter; - latexFormatter = texlabCfg.latexFormatter; + # -- Completion -- + completion.matcher = texlabCfg.completion.matcher; # -- Diagnostics -- diagnosticsDelay = texlabCfg.diagnostics.delay; diagnostics = { - allowedPatterns = texlabCfg.diagnostics.allowedPatterns; - ignoredPatterns = texlabCfg.diagnostics.ignoredPatterns; + inherit (texlabCfg.diagnostics) allowedPatterns ignoredPatterns; }; - # -- Latex Indent -- - latexindent = texlabCfg.latexindent; + # -- Experimental -- + experimental = texlabCfg.experimental; - # -- Completion -- - completion.matcher = texlabCfg.completion.matcher; + # -- Formatters -- + inherit (texlabCfg.formatter) formatterLineLength bibtexFormatter latexFormatter; # -- Inlay Hints -- inlayHints = texlabCfg.inlayHints; - # -- Experimental -- - experimental = texlabCfg.experimental; + # -- Latex Indent -- + latexindent = texlabCfg.latexindent; } # - # -- Forward Search -- + # -- Build -- // ( - if texlabCfg.forwardSearch.enable + if cfg.build.enable then { - forwardSearch = { - executable = "${texlabCfg.forwardSearch.package}/bin/${texlabCfg.forwardSearch.executable}"; - args = texlabCfg.forwardSearch.args; + build = { + inherit + (cfg.build) + onSave + useFileList + auxDirectory + logDirectory + pdfDirectory + filename + forwardSearchAfter + ; + inherit (builderCfg) args; + executable = "${builderCfg.package}/bin/${builderCfg.executable}"; }; } else {} @@ -460,6 +467,18 @@ in { else {} ) # + # -- Forward Search -- + // ( + if texlabCfg.forwardSearch.enable + then { + forwardSearch = { + executable = "${texlabCfg.forwardSearch.package}/bin/${texlabCfg.forwardSearch.executable}"; + args = texlabCfg.forwardSearch.args; + }; + } + else {} + ) + # # -- Symbols -- // ( if texlabCfg.symbols.enable @@ -481,25 +500,6 @@ in { else {} ) # - # -- Build -- - // ( - if cfg.build.enable - then { - build = { - executable = "${builderCfg.package}/bin/${builderCfg.executable}"; - args = builderCfg.args; - forwardSearchAfter = cfg.build.forwardSearchAfter; - onSave = cfg.build.onSave; - useFileList = cfg.build.useFileList; - auxDirectory = cfg.build.auxDirectory; - logDirectory = cfg.build.logDirectory; - pdfDirectory = cfg.build.pdfDirectory; - filename = cfg.build.filename; - }; - } - else {} - ) - # # -- Extra Settings -- // texlabCfg.extraLuaSettings ); From 4b2d169759adea4981a992571be4dbd970544114 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 14:52:44 -0700 Subject: [PATCH 36/65] Further Cleanup --- modules/plugins/languages/tex/lsp/texlab.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index fca7c759..58c55f5a 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -6,7 +6,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) listOf package str attrs ints enum either path nullOr submodule; + inherit (lib.types) attrs either enum ints listOf nullOr package path str submodule; inherit (lib.nvim.config) mkBool; inherit (builtins) isString map; @@ -50,7 +50,12 @@ in { }; completion.matcher = mkOption { - type = enum ["fuzzy" "fuzzy-ignore-case" "prefix" "prefix-ignore-case"]; + type = enum [ + "fuzzy" + "fuzzy-ignore-case" + "prefix" + "prefix-ignore-case" + ]; default = "fuzzy-ignore-case"; description = '' Modifies the algorithm used to filter the completion items returned to the client. Possibles values are: @@ -127,6 +132,7 @@ in { Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). ''; }; + labelDefinitionCommands = mkOption { type = listOf str; default = []; @@ -281,7 +287,7 @@ in { }; inlayHints = { - labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label-like` commands."; + labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label`-like commands."; labelReferences = mkBool true "When enabled, the server will return inlay hints for `\\ref``-like commands."; @@ -472,8 +478,8 @@ in { if texlabCfg.forwardSearch.enable then { forwardSearch = { + inherit (texlabCfg.forwardSearch) args; executable = "${texlabCfg.forwardSearch.package}/bin/${texlabCfg.forwardSearch.executable}"; - args = texlabCfg.forwardSearch.args; }; } else {} From ac062b23861ea4c38efac3f82d0203d4730c466a Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 17:15:00 -0700 Subject: [PATCH 37/65] Created PDF viewer framework --- modules/plugins/languages/tex/default.nix | 1 + .../languages/tex/pdfViewer/default.nix | 141 ++++++++++++++++++ .../tex/pdfViewer/viewers/default.nix | 6 + .../tex/pdfViewer/viewers/okular.nix | 42 ++++++ .../tex/pdfViewer/viewers/viewerTemplate.nix | 68 +++++++++ 5 files changed, 258 insertions(+) create mode 100644 modules/plugins/languages/tex/pdfViewer/default.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/default.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/okular.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 98ac5f1c..518361d7 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -13,6 +13,7 @@ in { ./treesitter.nix ./lsp ./build + ./pdfViewer ]; options.vim.languages.tex = { diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix new file mode 100644 index 00000000..890031dc --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -0,0 +1,141 @@ +{ + config, + lib, + pkgs, + ... +}: let + defaultPdfViewerName = "okular"; + + inherit (lib) mkOverride; + inherit (lib.options) mkOption; + inherit (lib.modules) mkIf; + inherit (lib.types) str package listOf; + inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; + inherit (lib.nvim.config) mkBool; + + cfg = config.vim.languages.tex; + viewersCfg = cfg.pdfViewer.viewers; + + enabledPdfViewersInfo = let + # This function will sort through the pdf viewer options and count how many + # pdf viewers have been enabled. + # If no viewers have been enabled, the count will be 0 and the name of the + # enabled viewer will be the default pdf viewer defined above. + getEnabledPdfViewersInfo = { + enabledPdfViewersCount ? 0, + index ? 0, + pdfViewerNamesList ? ( + filter ( + x: let + y = viewersCfg.${x}; + in ( + isAttrs y + && hasAttr "enable" y + && hasAttr "package" y + && hasAttr "executable" y + && hasAttr "args" y + ) + ) (attrNames viewersCfg) + ), + currentEnabledPdfViewerName ? defaultPdfViewerName, + }: let + # Get the name of the current pdf viewer being checked if it is enabled + currentPdfViewerName = elemAt pdfViewerNamesList index; + + # Get the current pdf viewer object + currentPdfViewer = viewersCfg.${currentPdfViewerName}; + + # Get the index that will be used for the next iteration + nextIndex = index + 1; + + # Increment the count that is recording the number of enabled pdf viewers if + # this viewer is enabled, otherwise leave it as is. + newEnabledPdfViewersCount = + if currentPdfViewer.enable + then enabledPdfViewersCount + 1 + else enabledPdfViewersCount; + + # If this pdf viewer is enabled, set is as the enabled viewer. + newEnabledPdfViewerName = + if currentPdfViewer.enable + then currentPdfViewerName + else currentEnabledPdfViewerName; + in + # Check that the end of the list of viewers has not been reached + if length pdfViewerNamesList > nextIndex + # If the end of the viewers list has not been reached, call the next iteration + # of the function to process the next viewer + then + getEnabledPdfViewersInfo { + inherit pdfViewerNamesList; + enabledPdfViewersCount = newEnabledPdfViewersCount; + index = nextIndex; + currentEnabledPdfViewerName = newEnabledPdfViewerName; + } + # If the end of the viewers list has been reached, then return the total number + # of viewers that have been enabled and the name of the last viewer that was enabled. + else { + count = newEnabledPdfViewersCount; + enabledViewerName = newEnabledPdfViewerName; + }; + in (getEnabledPdfViewersInfo {}); + + enabledPdfViewerCfg = viewersCfg.${enabledPdfViewersInfo.enabledViewerName}; + +in { + imports = [ + ./viewers + ]; + + options.vim.languages.tex.pdfViewer = { + enable = + mkBool ( + if enabledPdfViewersInfo.count > 1 + then throw "nvf-tex-language does not support having more than 1 pdf viewer enabled!" + else (enabledPdfViewersInfo.count == 1) + ) '' + Whether to enable configuring the pdf viewer. + + By enabling any of the pdfViewers, this option will be automatically set. + If you enable more than one pdf viewer then an error will be thrown. + ''; + + name = mkOption { + type = str; + default = enabledPdfViewerCfg.name; + description = '' + TODO + ''; + }; + + package = mkOption { + type = package; + default = enabledPdfViewerCfg.package; + description = '' + The package to set to use a custom viewer. + ''; + }; + + executable = mkOption { + type = str; + default = enabledPdfViewerCfg.executable; + description = '' + TODO + ''; + }; + + args = mkOption { + type = listOf str; + default = enabledPdfViewerCfg.args; + description = '' + TODO + ''; + }; + }; + + # If the pdf viewer has been enabled, but none of the individual viewers have been enabled, + # then enable the default viewer. + config = mkIf (cfg.enable && cfg.pdfViewer.enable && enabledPdfViewersInfo.count == 0) { + vim.languages.tex.pdfViewer.viewers.${defaultPdfViewerName}.enable = mkOverride 75 true; + }; +} diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/default.nix b/modules/plugins/languages/tex/pdfViewer/viewers/default.nix new file mode 100644 index 00000000..8874fc12 --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/default.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + imports = [ + ./okular.nix + ]; +} diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix b/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix new file mode 100644 index 00000000..4d0d90d4 --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix @@ -0,0 +1,42 @@ +{ + pkgs, + lib, + ... +} @ moduleInheritencePackage: let + # The name of the pdf viewer + name = "okular"; + + # The viewer template + template = import ./viewerTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) package str listOf; +in ( + template { + inherit name moduleInheritencePackage; + + options = { + enable = mkEnableOption "enable okular as the pdf file previewer."; + + package = mkOption { + type = package; + default = pkgs.okular; + description = "okular package"; + }; + + executable = mkOption { + type = str; + default = "okular"; + description = "The executable name to call the viewer."; + }; + + args = mkOption { + type = listOf str; + default = [ "--unique" "file:%p#src:%l%f" ]; + description = "Arguments to pass to the viewer."; + }; + }; + + args = viewerCfg: ( viewerCfg.args ); + } +) diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix b/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix new file mode 100644 index 00000000..64cb2ca2 --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix @@ -0,0 +1,68 @@ +# This function acts as a template for creating new pdf viewers. +# It enforces providing all the parameters required for creating +# a new pdf viewer for it to be able to work in the existing code. +# +# The first layer requirements are as follows: +{ + # This is the name of the pdf viewer, it will only be used internally and + # MUST match the .nix file that the pdf viewer is implemented in. + name, + # + # Module attribute set. This is the attribute set that the module that is + # defining a pdf viewer is passed as its input. + moduleInheritencePackage, + # + # These are the standard options for the pdf viewer just like creating any + # other module. Some options are required and are described below but + # it will also accept any other options that are provided to it. + options, + # + # These are the command line arguments that will accompany the executable + # when the view command is called. + # This is a function that will take in the cfg of its own pdf viewer. + # i.e. it will be called as "args cfg.pdfViewer.viewers.${name}" + args, + ... +}: let + # Inherit the necessary variables available to any module. + inherit (moduleInheritencePackage) lib config; + # + # Inherit other useful functions. + inherit (lib.modules) mkIf; + # + # Set the cfg variable + cfg = config.vim.languages.tex; + # + # Set the cfg of the viewer itself + viewerCfg = cfg.pdfViewer.viewers.${name}; +in { + # These are the options for the pdf viewer. It will accept any options + # provided to it but some options are mandatory: + options.vim.languages.tex.pdfViewer.viewers.${name} = ({ + # The enable option. This one is self explanatory. + enable, + # + # This is the package option for the pdf viewer. + package, + # + # This is the executable that will be used to call the pdf viewer. + # It, along with package will result in: + # "/bin/" + executable, + # + # Any other options provided are accepted. + ... + } @ opts: + opts) + options; + + # Check that the language, overall pdf viewing, and this pdf viewer have been enabled before making any + # config. + config = mkIf (cfg.enable && viewerCfg.enable) { + vim.languages.tex.pdfViewer = { + inherit name; + inherit (viewerCfg) package executable; + args = args viewerCfg; + }; + }; +} From 892f3d633632395a98ebebf5adb59986f6746048 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 18:14:51 -0700 Subject: [PATCH 38/65] PDF Viewer framework bug fixes and integrated functionallity into texlab lsp implementation --- modules/plugins/languages/tex/lsp/texlab.nix | 15 +++-- .../languages/tex/pdfViewer/default.nix | 56 +++++++++---------- .../tex/pdfViewer/viewers/okular.nix | 4 +- .../tex/pdfViewer/viewers/viewerTemplate.nix | 5 +- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 58c55f5a..06b8819e 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -226,31 +226,34 @@ in { package = mkOption { type = package; - default = pkgs.okular; + default = cfg.pdfViewer.package; description = '' The package to use as your PDF viewer. This viewer needs to support Synctex. + + By default it is set to the package of the pdfViewer option. ''; }; executable = mkOption { type = str; - default = "okular"; + default = cfg.pdfViewer.executable; description = '' Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + + By default it is set to the executable of the pdfViewer option. ''; }; args = mkOption { type = listOf str; - default = [ - "--unique" - "file:%p#src:%l%f" - ]; + default = cfg.pdfViewer.args; description = '' Defines additional arguments that are passed to the configured previewer to perform the forward search. The placeholders %f, %p, %l will be replaced by the server. + By default it is set to the args of the pdfViewer option. + Placeholders: - %f: The path of the current TeX file. - %p: The path of the current PDF file. diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix index 890031dc..e27b26a0 100644 --- a/modules/plugins/languages/tex/pdfViewer/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -1,17 +1,13 @@ { config, lib, - pkgs, ... }: let defaultPdfViewerName = "okular"; - inherit (lib) mkOverride; inherit (lib.options) mkOption; - inherit (lib.modules) mkIf; inherit (lib.types) str package listOf; inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; - inherit (lib.nvim.config) mkBool; cfg = config.vim.languages.tex; viewersCfg = cfg.pdfViewer.viewers; @@ -52,7 +48,10 @@ # this viewer is enabled, otherwise leave it as is. newEnabledPdfViewersCount = if currentPdfViewer.enable - then enabledPdfViewersCount + 1 + then + if enabledPdfViewersCount > 0 + then throw "nvf-tex-language does not support having more than 1 pdf viewer enabled!" + else enabledPdfViewersCount + 1 else enabledPdfViewersCount; # If this pdf viewer is enabled, set is as the enabled viewer. @@ -81,30 +80,22 @@ in (getEnabledPdfViewersInfo {}); enabledPdfViewerCfg = viewersCfg.${enabledPdfViewersInfo.enabledViewerName}; - in { imports = [ ./viewers ]; options.vim.languages.tex.pdfViewer = { - enable = - mkBool ( - if enabledPdfViewersInfo.count > 1 - then throw "nvf-tex-language does not support having more than 1 pdf viewer enabled!" - else (enabledPdfViewersInfo.count == 1) - ) '' - Whether to enable configuring the pdf viewer. - - By enabling any of the pdfViewers, this option will be automatically set. - If you enable more than one pdf viewer then an error will be thrown. - ''; - name = mkOption { type = str; default = enabledPdfViewerCfg.name; description = '' - TODO + The name of the pdf viewer to use. + + This value will be automatically set when any of the viewers are enabled. + + Setting this option option manually is not recommended but can be used for some very technical nix-ing. + If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. ''; }; @@ -112,7 +103,12 @@ in { type = package; default = enabledPdfViewerCfg.package; description = '' - The package to set to use a custom viewer. + The package of the pdf viewer to use. + + This value will be automatically set when any of the viewers are enabled. + + Setting this option option manually is not recommended but can be used for some very technical nix-ing. + If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. ''; }; @@ -120,7 +116,12 @@ in { type = str; default = enabledPdfViewerCfg.executable; description = '' - TODO + The executable for the pdf viewer to use. + + This value will be automatically set when any of the viewers are enabled. + + Setting this option option manually is not recommended but can be used for some very technical nix-ing. + If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. ''; }; @@ -128,14 +129,13 @@ in { type = listOf str; default = enabledPdfViewerCfg.args; description = '' - TODO + The command line arguments to use when calling the pdf viewer command. + + This value will be automatically set when any of the viewers are enabled. + + Setting this option option manually is not recommended but can be used for some very technical nix-ing. + If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. ''; }; }; - - # If the pdf viewer has been enabled, but none of the individual viewers have been enabled, - # then enable the default viewer. - config = mkIf (cfg.enable && cfg.pdfViewer.enable && enabledPdfViewersInfo.count == 0) { - vim.languages.tex.pdfViewer.viewers.${defaultPdfViewerName}.enable = mkOverride 75 true; - }; } diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix b/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix index 4d0d90d4..74cb88b7 100644 --- a/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix +++ b/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix @@ -32,11 +32,11 @@ in ( args = mkOption { type = listOf str; - default = [ "--unique" "file:%p#src:%l%f" ]; + default = ["--unique" "file:%p#src:%l%f"]; description = "Arguments to pass to the viewer."; }; }; - args = viewerCfg: ( viewerCfg.args ); + argsFunction = viewerCfg: (viewerCfg.args); } ) diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix b/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix index 64cb2ca2..280cf483 100644 --- a/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix +++ b/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix @@ -21,7 +21,7 @@ # when the view command is called. # This is a function that will take in the cfg of its own pdf viewer. # i.e. it will be called as "args cfg.pdfViewer.viewers.${name}" - args, + argsFunction, ... }: let # Inherit the necessary variables available to any module. @@ -59,10 +59,11 @@ in { # Check that the language, overall pdf viewing, and this pdf viewer have been enabled before making any # config. config = mkIf (cfg.enable && viewerCfg.enable) { + # vim.languages.tex.pdfViewer.viewers.${name} = { vim.languages.tex.pdfViewer = { inherit name; inherit (viewerCfg) package executable; - args = args viewerCfg; + args = argsFunction viewerCfg; }; }; } From 4a581e984ce423be2e0c32067b0d409aaf3e8bc3 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 18:56:32 -0700 Subject: [PATCH 39/65] Added more pdf viewer options --- .../tex/pdfViewer/viewers/custom.nix | 42 +++++++++++++ .../tex/pdfViewer/viewers/default.nix | 4 ++ .../tex/pdfViewer/viewers/qpdfview.nix | 42 +++++++++++++ .../tex/pdfViewer/viewers/sioyek.nix | 59 +++++++++++++++++++ .../tex/pdfViewer/viewers/zathura.nix | 42 +++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/custom.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/qpdfview.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/sioyek.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/zathura.nix diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/custom.nix b/modules/plugins/languages/tex/pdfViewer/viewers/custom.nix new file mode 100644 index 00000000..ec4b331b --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/custom.nix @@ -0,0 +1,42 @@ +{ + pkgs, + lib, + ... +} @ moduleInheritencePackage: let + # The name of the pdf viewer + name = "custom"; + + # The viewer template + template = import ./viewerTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) package str listOf; +in ( + template { + inherit name moduleInheritencePackage; + + options = { + enable = mkEnableOption "enable using a custom pdf viewer."; + + package = mkOption { + type = package; + example = pkgs.okular; + description = "custom viewer package"; + }; + + executable = mkOption { + type = str; + example = "okular"; + description = "The executable name to call the viewer."; + }; + + args = mkOption { + type = listOf str; + example = ["--unique" "file:%p#src:%l%f"]; + description = "Arguments to pass to the viewer."; + }; + }; + + argsFunction = viewerCfg: (viewerCfg.args); + } +) diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/default.nix b/modules/plugins/languages/tex/pdfViewer/viewers/default.nix index 8874fc12..36a0338d 100644 --- a/modules/plugins/languages/tex/pdfViewer/viewers/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/viewers/default.nix @@ -1,6 +1,10 @@ { ... }: { imports = [ + ./custom.nix ./okular.nix + ./sioyek.nix + ./qpdfview.nix + ./zathura.nix ]; } diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/qpdfview.nix b/modules/plugins/languages/tex/pdfViewer/viewers/qpdfview.nix new file mode 100644 index 00000000..dafe93f4 --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/qpdfview.nix @@ -0,0 +1,42 @@ +{ + pkgs, + lib, + ... +} @ moduleInheritencePackage: let + # The name of the pdf viewer + name = "qpdfview"; + + # The viewer template + template = import ./viewerTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) package str listOf; +in ( + template { + inherit name moduleInheritencePackage; + + options = { + enable = mkEnableOption "enable qpdfview as the pdf file previewer."; + + package = mkOption { + type = package; + default = pkgs.qpdfview; + description = "qpdfview package"; + }; + + executable = mkOption { + type = str; + default = "qpdfview"; + description = "The executable name to call the viewer."; + }; + + args = mkOption { + type = listOf str; + default = ["--unique" "%p#src:%f:%l:1"]; + description = "Arguments to pass to the viewer."; + }; + }; + + argsFunction = viewerCfg: (viewerCfg.args); + } +) diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/sioyek.nix b/modules/plugins/languages/tex/pdfViewer/viewers/sioyek.nix new file mode 100644 index 00000000..9ea9f3f8 --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/sioyek.nix @@ -0,0 +1,59 @@ +{ + pkgs, + lib, + ... +} @ moduleInheritencePackage: let + # The name of the pdf viewer + name = "sioyek"; + + # The viewer template + template = import ./viewerTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) package str listOf; +in ( + template { + inherit name moduleInheritencePackage; + + options = { + enable = mkEnableOption "enable sioyek as the pdf file previewer."; + + package = mkOption { + type = package; + default = pkgs.sioyek; + description = "sioyek package"; + }; + + executable = mkOption { + type = str; + default = "sioyek"; + description = "The executable name to call the viewer."; + }; + + args = mkOption { + type = listOf str; + default = [ + "--reuse-window" + "--execute-command" + "toggle_synctex" + "--inverse-search" + "texlab inverse-search -i \"%%1\" -l %%2" + "--forward-search-file" + "%f" + "--forward-search-line" + "%l" + "%p" + ]; + description = '' + Arguments to pass to the viewer. + + By default, this is the only viewer that supports the inverse search feature by + command line arguments and doesn't explicitly require extra tinkering else where + in your config. + ''; + }; + }; + + argsFunction = viewerCfg: (viewerCfg.args); + } +) diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/zathura.nix b/modules/plugins/languages/tex/pdfViewer/viewers/zathura.nix new file mode 100644 index 00000000..b1589b5a --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/viewers/zathura.nix @@ -0,0 +1,42 @@ +{ + pkgs, + lib, + ... +} @ moduleInheritencePackage: let + # The name of the pdf viewer + name = "zathura"; + + # The viewer template + template = import ./viewerTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) package str listOf; +in ( + template { + inherit name moduleInheritencePackage; + + options = { + enable = mkEnableOption "enable zathura as the pdf file previewer."; + + package = mkOption { + type = package; + default = pkgs.zathura; + description = "zathura package"; + }; + + executable = mkOption { + type = str; + default = "zathura"; + description = "The executable name to call the viewer."; + }; + + args = mkOption { + type = listOf str; + default = ["--synctex-forward" "%l:1:%f" "%p"]; + description = "Arguments to pass to the viewer."; + }; + }; + + argsFunction = viewerCfg: (viewerCfg.args); + } +) From 594d7b434b3b5048c2c347b5ac02e8345d59affb Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 19:15:22 -0700 Subject: [PATCH 40/65] Reorganized file and options structure for more intuitive use --- .../tex/pdfViewer/{viewers => }/custom.nix | 0 .../plugins/languages/tex/pdfViewer/default.nix | 16 ++++++++++------ .../tex/pdfViewer/{viewers => }/okular.nix | 0 .../tex/pdfViewer/{viewers => }/qpdfview.nix | 0 .../tex/pdfViewer/{viewers => }/sioyek.nix | 0 .../pdfViewer/{viewers => }/viewerTemplate.nix | 10 ++++------ .../languages/tex/pdfViewer/viewers/default.nix | 10 ---------- .../tex/pdfViewer/{viewers => }/zathura.nix | 0 8 files changed, 14 insertions(+), 22 deletions(-) rename modules/plugins/languages/tex/pdfViewer/{viewers => }/custom.nix (100%) rename modules/plugins/languages/tex/pdfViewer/{viewers => }/okular.nix (100%) rename modules/plugins/languages/tex/pdfViewer/{viewers => }/qpdfview.nix (100%) rename modules/plugins/languages/tex/pdfViewer/{viewers => }/sioyek.nix (100%) rename modules/plugins/languages/tex/pdfViewer/{viewers => }/viewerTemplate.nix (85%) delete mode 100644 modules/plugins/languages/tex/pdfViewer/viewers/default.nix rename modules/plugins/languages/tex/pdfViewer/{viewers => }/zathura.nix (100%) diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/custom.nix b/modules/plugins/languages/tex/pdfViewer/custom.nix similarity index 100% rename from modules/plugins/languages/tex/pdfViewer/viewers/custom.nix rename to modules/plugins/languages/tex/pdfViewer/custom.nix diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix index e27b26a0..43a16907 100644 --- a/modules/plugins/languages/tex/pdfViewer/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -10,7 +10,7 @@ inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; cfg = config.vim.languages.tex; - viewersCfg = cfg.pdfViewer.viewers; + viewerCfg = cfg.pdfViewer; enabledPdfViewersInfo = let # This function will sort through the pdf viewer options and count how many @@ -23,7 +23,7 @@ pdfViewerNamesList ? ( filter ( x: let - y = viewersCfg.${x}; + y = viewerCfg.${x}; in ( isAttrs y && hasAttr "enable" y @@ -31,7 +31,7 @@ && hasAttr "executable" y && hasAttr "args" y ) - ) (attrNames viewersCfg) + ) (attrNames viewerCfg) ), currentEnabledPdfViewerName ? defaultPdfViewerName, }: let @@ -39,7 +39,7 @@ currentPdfViewerName = elemAt pdfViewerNamesList index; # Get the current pdf viewer object - currentPdfViewer = viewersCfg.${currentPdfViewerName}; + currentPdfViewer = viewerCfg.${currentPdfViewerName}; # Get the index that will be used for the next iteration nextIndex = index + 1; @@ -79,10 +79,14 @@ }; in (getEnabledPdfViewersInfo {}); - enabledPdfViewerCfg = viewersCfg.${enabledPdfViewersInfo.enabledViewerName}; + enabledPdfViewerCfg = viewerCfg.${enabledPdfViewersInfo.enabledViewerName}; in { imports = [ - ./viewers + ./custom.nix + ./okular.nix + ./sioyek.nix + ./qpdfview.nix + ./zathura.nix ]; options.vim.languages.tex.pdfViewer = { diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/okular.nix b/modules/plugins/languages/tex/pdfViewer/okular.nix similarity index 100% rename from modules/plugins/languages/tex/pdfViewer/viewers/okular.nix rename to modules/plugins/languages/tex/pdfViewer/okular.nix diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/qpdfview.nix b/modules/plugins/languages/tex/pdfViewer/qpdfview.nix similarity index 100% rename from modules/plugins/languages/tex/pdfViewer/viewers/qpdfview.nix rename to modules/plugins/languages/tex/pdfViewer/qpdfview.nix diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/sioyek.nix b/modules/plugins/languages/tex/pdfViewer/sioyek.nix similarity index 100% rename from modules/plugins/languages/tex/pdfViewer/viewers/sioyek.nix rename to modules/plugins/languages/tex/pdfViewer/sioyek.nix diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix similarity index 85% rename from modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix rename to modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix index 280cf483..7b2ba93b 100644 --- a/modules/plugins/languages/tex/pdfViewer/viewers/viewerTemplate.nix +++ b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix @@ -20,7 +20,7 @@ # These are the command line arguments that will accompany the executable # when the view command is called. # This is a function that will take in the cfg of its own pdf viewer. - # i.e. it will be called as "args cfg.pdfViewer.viewers.${name}" + # i.e. it will be called as "args cfg.pdfViewer.${name}" argsFunction, ... }: let @@ -34,11 +34,11 @@ cfg = config.vim.languages.tex; # # Set the cfg of the viewer itself - viewerCfg = cfg.pdfViewer.viewers.${name}; + viewerCfg = cfg.pdfViewer.${name}; in { # These are the options for the pdf viewer. It will accept any options # provided to it but some options are mandatory: - options.vim.languages.tex.pdfViewer.viewers.${name} = ({ + options.vim.languages.tex.pdfViewer.${name} = ({ # The enable option. This one is self explanatory. enable, # @@ -56,10 +56,8 @@ in { opts) options; - # Check that the language, overall pdf viewing, and this pdf viewer have been enabled before making any - # config. + # Check that the language and this pdf viewer have been enabled before making any config. config = mkIf (cfg.enable && viewerCfg.enable) { - # vim.languages.tex.pdfViewer.viewers.${name} = { vim.languages.tex.pdfViewer = { inherit name; inherit (viewerCfg) package executable; diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/default.nix b/modules/plugins/languages/tex/pdfViewer/viewers/default.nix deleted file mode 100644 index 36a0338d..00000000 --- a/modules/plugins/languages/tex/pdfViewer/viewers/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ ... }: -{ - imports = [ - ./custom.nix - ./okular.nix - ./sioyek.nix - ./qpdfview.nix - ./zathura.nix - ]; -} diff --git a/modules/plugins/languages/tex/pdfViewer/viewers/zathura.nix b/modules/plugins/languages/tex/pdfViewer/zathura.nix similarity index 100% rename from modules/plugins/languages/tex/pdfViewer/viewers/zathura.nix rename to modules/plugins/languages/tex/pdfViewer/zathura.nix From 08a77485aa15b0815f6edaf8b7823caf43e5e757 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Mon, 10 Feb 2025 15:24:39 -0700 Subject: [PATCH 41/65] Fixed typos and formatting --- .../languages/tex/build/builders/builderTemplate.nix | 4 ++-- .../plugins/languages/tex/build/builders/latexmk.nix | 6 +++--- .../languages/tex/build/builders/tectonic.nix | 6 +++--- modules/plugins/languages/tex/default.nix | 2 +- modules/plugins/languages/tex/lsp/texlab.nix | 12 ++++++------ modules/plugins/languages/tex/pdfViewer/custom.nix | 4 ++-- modules/plugins/languages/tex/pdfViewer/okular.nix | 4 ++-- modules/plugins/languages/tex/pdfViewer/qpdfview.nix | 4 ++-- modules/plugins/languages/tex/pdfViewer/sioyek.nix | 4 ++-- .../languages/tex/pdfViewer/viewerTemplate.nix | 4 ++-- modules/plugins/languages/tex/pdfViewer/zathura.nix | 4 ++-- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/builderTemplate.nix b/modules/plugins/languages/tex/build/builders/builderTemplate.nix index c9cc8163..02d20412 100644 --- a/modules/plugins/languages/tex/build/builders/builderTemplate.nix +++ b/modules/plugins/languages/tex/build/builders/builderTemplate.nix @@ -10,7 +10,7 @@ # # Module attribute set. This is the attribute set that the module that is # defining a builder is passed as its input. - moduleInheritencePackage, + moduleInheritancePackage, # # These are the standard options for the builder just like creating any # other module. Some options are required and are described below but @@ -25,7 +25,7 @@ ... }: let # Inherit the necessary variables available to any module. - inherit (moduleInheritencePackage) lib config; + inherit (moduleInheritancePackage) lib config; # # Inherit other useful functions. inherit (lib.modules) mkIf; diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index edc46584..4d024eb3 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -3,7 +3,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the builder name = "latexmk"; @@ -14,14 +14,14 @@ inherit (lib.types) bool package str; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk"; package = mkOption { type = package; - default = (pkgs.texlive.withPackages (ps: [ ps.latexmk ])); + default = pkgs.texlive.withPackages (ps: [ps.latexmk]); description = "latexmk package"; }; diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index ec6e253c..1b131b33 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -3,7 +3,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the builder name = "tectonic"; @@ -18,7 +18,7 @@ cfg = config.vim.languages.tex; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; @@ -58,7 +58,7 @@ in ( description = '' Rerun the TeX engine exactly this many times after the first. - Setting this value to 0 will diable setting this option. + Setting this value to 0 will disable setting this option. ''; }; diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 518361d7..252e8615 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -35,7 +35,7 @@ in { If no filetype can be determined automatically then by default it will fallback to plaintex. This option will enable setting the tex flavor in your lua config and you can set its value - useing the `vim.languages.tex.lsp.extraOpts.texFlavor.flavor = ` in your nvf config. + using the `vim.languages.tex.lsp.extraOpts.texFlavor.flavor = ` in your nvf config. Setting this option to `false` will omit the `vim.g.tex_flavor = ` line from your lua config entirely (unless you manually set it elsewhere of course). diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 06b8819e..5677d958 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -169,11 +169,11 @@ in { description = '' Allows associating a label definition command with a custom prefix. Consider, ``` - \newcommand{\thm}[1]{\label{thm:#1}} - \thm{foo} + \newcommand{\theorem}[1]{\label{theorem:#1}} + \theorem{foo} ``` - Then setting `texlab.experimental.labelDefinitionPrefixes` to `[["thm", "thm:"]]` and adding "thm" - to `texlab.experimental.labelDefinitionCommands` will make the server recognize the `thm:foo` label. + Then setting `texlab.experimental.labelDefinitionPrefixes` to `[["theorem", "theorem:"]]` and adding "theorem" + to `texlab.experimental.labelDefinitionCommands` will make the server recognize the `theorem:foo` label. ''; }; @@ -221,7 +221,7 @@ in { Enable this option if you want to have the compiled document appear in your chosen PDF viewer. For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - Note this is not all the options, but can act as a guide to help you allong with custom configs. + Note this is not all the options, but can act as a guide to help you along with custom configs. ''; package = mkOption { @@ -405,7 +405,7 @@ in { - description: If set, the server will try to match a label to environment and append its number. - default: false - Note: This functionallity may not be working, please follow https://github.com/latex-lsp/texlab/pull/1311 + Note: This functionality may not be working, please follow https://github.com/latex-lsp/texlab/pull/1311 for status updates. ''; }; diff --git a/modules/plugins/languages/tex/pdfViewer/custom.nix b/modules/plugins/languages/tex/pdfViewer/custom.nix index ec4b331b..189663fe 100644 --- a/modules/plugins/languages/tex/pdfViewer/custom.nix +++ b/modules/plugins/languages/tex/pdfViewer/custom.nix @@ -2,7 +2,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the pdf viewer name = "custom"; @@ -13,7 +13,7 @@ inherit (lib.types) package str listOf; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "enable using a custom pdf viewer."; diff --git a/modules/plugins/languages/tex/pdfViewer/okular.nix b/modules/plugins/languages/tex/pdfViewer/okular.nix index 74cb88b7..e341fa4d 100644 --- a/modules/plugins/languages/tex/pdfViewer/okular.nix +++ b/modules/plugins/languages/tex/pdfViewer/okular.nix @@ -2,7 +2,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the pdf viewer name = "okular"; @@ -13,7 +13,7 @@ inherit (lib.types) package str listOf; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "enable okular as the pdf file previewer."; diff --git a/modules/plugins/languages/tex/pdfViewer/qpdfview.nix b/modules/plugins/languages/tex/pdfViewer/qpdfview.nix index dafe93f4..ef294bcf 100644 --- a/modules/plugins/languages/tex/pdfViewer/qpdfview.nix +++ b/modules/plugins/languages/tex/pdfViewer/qpdfview.nix @@ -2,7 +2,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the pdf viewer name = "qpdfview"; @@ -13,7 +13,7 @@ inherit (lib.types) package str listOf; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "enable qpdfview as the pdf file previewer."; diff --git a/modules/plugins/languages/tex/pdfViewer/sioyek.nix b/modules/plugins/languages/tex/pdfViewer/sioyek.nix index 9ea9f3f8..a4c647b1 100644 --- a/modules/plugins/languages/tex/pdfViewer/sioyek.nix +++ b/modules/plugins/languages/tex/pdfViewer/sioyek.nix @@ -2,7 +2,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the pdf viewer name = "sioyek"; @@ -13,7 +13,7 @@ inherit (lib.types) package str listOf; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "enable sioyek as the pdf file previewer."; diff --git a/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix index 7b2ba93b..dd81b7a4 100644 --- a/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix +++ b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix @@ -10,7 +10,7 @@ # # Module attribute set. This is the attribute set that the module that is # defining a pdf viewer is passed as its input. - moduleInheritencePackage, + moduleInheritancePackage, # # These are the standard options for the pdf viewer just like creating any # other module. Some options are required and are described below but @@ -25,7 +25,7 @@ ... }: let # Inherit the necessary variables available to any module. - inherit (moduleInheritencePackage) lib config; + inherit (moduleInheritancePackage) lib config; # # Inherit other useful functions. inherit (lib.modules) mkIf; diff --git a/modules/plugins/languages/tex/pdfViewer/zathura.nix b/modules/plugins/languages/tex/pdfViewer/zathura.nix index b1589b5a..99d95498 100644 --- a/modules/plugins/languages/tex/pdfViewer/zathura.nix +++ b/modules/plugins/languages/tex/pdfViewer/zathura.nix @@ -2,7 +2,7 @@ pkgs, lib, ... -} @ moduleInheritencePackage: let +} @ moduleInheritancePackage: let # The name of the pdf viewer name = "zathura"; @@ -13,7 +13,7 @@ inherit (lib.types) package str listOf; in ( template { - inherit name moduleInheritencePackage; + inherit name moduleInheritancePackage; options = { enable = mkEnableOption "enable zathura as the pdf file previewer."; From b30727e033587055655ff8557d5d67c4faf443fc Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Mon, 10 Feb 2025 17:35:57 -0700 Subject: [PATCH 42/65] Created mkEnableTreesitterOption in the extendend library --- lib/types/default.nix | 2 +- lib/types/languages.nix | 11 +++++++++-- modules/plugins/languages/tex/treesitter.nix | 12 +++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/types/default.nix b/lib/types/default.nix index 66adfbbc..352fb89d 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -9,6 +9,6 @@ in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; - inherit (typesLanguage) diagnostics mkGrammarOption; + inherit (typesLanguage) diagnostics mkGrammarOption mkEnableTreesitterOption; inherit (customTypes) char hexColor mergelessListOf deprecatedSingleOrListOf; } diff --git a/lib/types/languages.nix b/lib/types/languages.nix index b1865c41..29639047 100644 --- a/lib/types/languages.nix +++ b/lib/types/languages.nix @@ -1,7 +1,7 @@ {lib}: let inherit (lib.options) mkOption mkPackageOption; inherit (lib.attrsets) attrNames; - inherit (lib.types) listOf either enum submodule package; + inherit (lib.types) listOf either enum submodule package bool; diagnosticSubmodule = _: { options = { @@ -32,6 +32,13 @@ mkPackageOption pkgs ["${grammar} treesitter"] { default = ["vimPlugins" "nvim-treesitter" "builtGrammars" grammar]; }; + + mkEnableTreesitterOption = config: language: + mkOption { + type = bool; + default = config.vim.languages.enableTreesitter; + description = "Whether to enable ${language} treesitter"; + }; in { - inherit diagnostics diagnosticSubmodule mkGrammarOption; + inherit diagnostics diagnosticSubmodule mkGrammarOption mkEnableTreesitterOption; } diff --git a/modules/plugins/languages/tex/treesitter.nix b/modules/plugins/languages/tex/treesitter.nix index 44459afb..98185ba8 100644 --- a/modules/plugins/languages/tex/treesitter.nix +++ b/modules/plugins/languages/tex/treesitter.nix @@ -4,21 +4,23 @@ lib, ... }: let - inherit (lib.options) mkEnableOption; + # inherit (lib.options) mkEnableOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.nvim.types) mkGrammarOption mkEnableTreesitterOption; cfg = config.vim.languages.tex; - mkEnableTreesitterOption = description: mkEnableOption description // {default = config.vim.languages.enableTreesitter;}; + # mkEnableTreesitterOption = description: mkEnableOption description // {default = config.vim.languages.enableTreesitter;}; in { options.vim.languages.tex.treesitter = { latex = { - enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; + # enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; + enable = mkEnableTreesitterOption config "latex"; package = mkGrammarOption pkgs "latex"; }; bibtex = { - enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; + # enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; + enable = mkEnableTreesitterOption config "bibtex"; package = mkGrammarOption pkgs "bibtex"; }; }; From 3c8fde89cc0f6dbf51894da841bd4c5cbbfa5c69 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 18:16:07 -0700 Subject: [PATCH 43/65] Rebase & Merge --- .../conform-nvim/builders/builderTemplate.nix | 66 ++++++ .../conform-nvim/builders/default.nix | 70 ++++++ .../conform-nvim/builders/latexmk.nix | 57 +++++ .../conform-nvim/builders/tectonic.nix | 203 ++++++++++++++++++ 4 files changed, 396 insertions(+) create mode 100644 modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix create mode 100644 modules/plugins/formatter/conform-nvim/builders/default.nix create mode 100644 modules/plugins/formatter/conform-nvim/builders/latexmk.nix create mode 100644 modules/plugins/formatter/conform-nvim/builders/tectonic.nix diff --git a/modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix b/modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix new file mode 100644 index 00000000..02d20412 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix @@ -0,0 +1,66 @@ +# This function acts as a template for creating new builders. +# It enforces providing all the parameters required for creating +# a new builder for it to be able to work in the existing code. +# +# The first layer requirements are as follows: +{ + # This is the name of the builder, it will only be used internally and + # should match the .nix file that the builder is implemented in. + name, + # + # Module attribute set. This is the attribute set that the module that is + # defining a builder is passed as its input. + moduleInheritancePackage, + # + # These are the standard options for the builder just like creating any + # other module. Some options are required and are described below but + # it will also accept any other options that are provided to it. + options, + # + # These are the command line arguments that will accompany the executable + # when the build command is called. + # This is a function that will take in the cfg of its own builder. + # i.e. will be called as "args cfg.build.builders.${name}" + args, + ... +}: let + # Inherit the necessary variables available to any module. + inherit (moduleInheritancePackage) lib config; + # + # Inherit other useful functions. + inherit (lib.modules) mkIf; + # + # Set the cfg variable + cfg = config.vim.languages.tex; +in { + # These are the options for the builder. It will accept any options + # provided to it but some options are mandatory: + options.vim.languages.tex.build.builders.${name} = ({ + # The enable option. This one is self explanatory. + enable, + # + # This is the package option for the builder. + package, + # + # This is the executable that will be used to call the builder. + # It, along with package will result in: + # "/bin/" + executable, + # + # Any other options provided are accepted. + ... + } @ opts: + opts) + options; + + # Check that the language and this builder have been enabled + # before making any config. + config = mkIf (cfg.enable && cfg.build.builders.${name}.enable) { + vim.languages.tex.build.builder = { + inherit name; + package = cfg.build.builders.${name}.package; + executable = cfg.build.builders.${name}.executable; + args = args cfg.build.builders.${name}; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/builders/default.nix b/modules/plugins/formatter/conform-nvim/builders/default.nix new file mode 100644 index 00000000..4586b768 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/builders/default.nix @@ -0,0 +1,70 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) enum listOf package str; + inherit (lib.nvim.config) mkBool; + inherit (builtins) attrNames filter isAttrs hasAttr elemAt length; + + cfg = config.vim.languages.tex; +in { + imports = [ + ./latexmk.nix + ./tectonic.nix + ]; + + options.vim.languages.tex.build.builder = { + name = mkOption { + type = enum (attrNames cfg.build.builders); + default = "latexmk"; + description = '' + The tex builder to use. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + Setting this parameter to the name of a declared builder will + not automatically enable that builder. + ''; + }; + args = mkOption { + type = listOf str; + default = [ + "-pdf" + "%f" + ]; + description = '' + The list of args to pass to the builder. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; + }; + package = mkOption { + type = package; + default = pkgs.texlive.withPackages (ps: [ps.latexmk]); + description = '' + The tex builder package to use. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; + }; + executable = mkOption { + type = str; + default = "latexmk"; + description = '' + The tex builder executable to use. + + This is just the default custom option. By setting any of the + builders to true, this will be overwritten by that builder's + parameters. + ''; + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/builders/latexmk.nix b/modules/plugins/formatter/conform-nvim/builders/latexmk.nix new file mode 100644 index 00000000..4d024eb3 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/builders/latexmk.nix @@ -0,0 +1,57 @@ +# TODO: I need testing. +{ + pkgs, + lib, + ... +} @ moduleInheritancePackage: let + # The name of the builder + name = "latexmk"; + + # The builder template + template = import ./builderTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) bool package str; +in ( + template { + inherit name moduleInheritancePackage; + + options = { + enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk"; + + package = mkOption { + type = package; + default = pkgs.texlive.withPackages (ps: [ps.latexmk]); + description = "latexmk package"; + }; + + executable = mkOption { + type = str; + default = "latexmk"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # Flag options + pdfOutput = mkOption { + type = bool; + default = true; + example = false; + description = "Insure the output file is a pdf."; + }; + }; + + args = builderCfg: ( + # Flags + ( + if builderCfg.pdfOutput + then ["-pdf"] + else [] + ) + # Base args + ++ [ + "-quiet" + "%f" + ] + ); + } +) diff --git a/modules/plugins/formatter/conform-nvim/builders/tectonic.nix b/modules/plugins/formatter/conform-nvim/builders/tectonic.nix new file mode 100644 index 00000000..1b131b33 --- /dev/null +++ b/modules/plugins/formatter/conform-nvim/builders/tectonic.nix @@ -0,0 +1,203 @@ +{ + config, + pkgs, + lib, + ... +} @ moduleInheritancePackage: let + # The name of the builder + name = "tectonic"; + + # The builder template + template = import ./builderTemplate.nix; + + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) enum ints listOf package str; + inherit (lib.nvim.config) mkBool; + inherit (builtins) concatLists elem map toString; + + cfg = config.vim.languages.tex; +in ( + template { + inherit name moduleInheritancePackage; + + options = { + enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; + + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; + }; + + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # -- Flags -- + keepIntermediates = mkBool false '' + Keep the intermediate files generated during processing. + + If texlab is reporting build errors when there shouldn't be, disable this option. + ''; + keepLogs = mkBool true '' + Keep the log files generated during processing. + + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkBool false "Use only resource files cached locally"; + synctex = mkBool true "Generate SyncTeX data"; + untrustedInput = mkBool false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = '' + Rerun the TeX engine exactly this many times after the first. + + Setting this value to 0 will disable setting this option. + ''; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; + }; + + args = builderCfg: ( + # Base args + [ + "-X" + "compile" + "%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 [] + ) + # 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 [] + ) + ++ (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 [] + ) + # 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 [] + ) + ); + } +) From 44c007f76e3648d9bf2740a1405c5defcd54b8e1 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 19:37:14 -0700 Subject: [PATCH 44/65] 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."; + } + ]; + }; } From 29d78156acea9212a7926184538b92972fe03f6f Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:40:26 -0700 Subject: [PATCH 45/65] Added code/keyword md escaping for documentation in modules/plugins/languages/tex/build/default.nix Co-authored-by: raf --- modules/plugins/languages/tex/build/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/build/default.nix b/modules/plugins/languages/tex/build/default.nix index 78f13588..3daa0ea7 100644 --- a/modules/plugins/languages/tex/build/default.nix +++ b/modules/plugins/languages/tex/build/default.nix @@ -61,7 +61,7 @@ in { onSave = mkBool false "Set this property to true if you want to compile the project after saving a file."; useFileList = mkBool false '' - When set to true, the server will use the .fls files produced by the TeX engine as an additional input for the project detection. + When set to `true`, the server will use the `.fls` files produced by the TeX engine as an additional input for the project detection. Note that enabling this property might have an impact on performance. ''; From 290f4e5b08c6119fe536c4369a002fb3d7d07702 Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:41:14 -0700 Subject: [PATCH 46/65] Added code/keyword md escaping for documentation in modules/plugins/languages/tex/default.nix Co-authored-by: raf --- modules/plugins/languages/tex/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 252e8615..be77a49e 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -26,7 +26,7 @@ in { default = false; example = true; description = '' - Whether to set the vim.g.tex_flavor (g:tex_flavor) option in your lua config. + Whether to set the `vim.g.tex_flavor` (`g:tex_flavor`) option in your Lua config. When opening a .tex file vim will try to automatically try to determine the file type from the three options: plaintex (for plain TeX), context (for ConTeXt), or tex (for LaTeX). From 937f48d4c596d8391f4eac17200ecbeb60cf18be Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:42:14 -0700 Subject: [PATCH 47/65] Removed duplicate "Whether to enable" in documentation for modules/plugins/languages/tex/build/builders/tectonic.nix Co-authored-by: raf --- modules/plugins/languages/tex/build/builders/tectonic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 7513350d..315b13de 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -22,7 +22,7 @@ in ( inherit name moduleInheritancePackage; options = { - enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; + enable = mkEnableOption "Tex Compilation Via Tectonic"; package = mkOption { type = package; From 6c3efb5b7963413c5e840d3257dffff45011439b Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:43:46 -0700 Subject: [PATCH 48/65] Removed duplicate "Whether to enable" in documentation for modules/plugins/languages/tex/build/builders/latexmk.nix Co-authored-by: raf --- modules/plugins/languages/tex/build/builders/latexmk.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index c1f17917..9037fd6a 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -18,7 +18,7 @@ in ( inherit name moduleInheritancePackage; options = { - enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk"; + enable = mkEnableOption "Tex Compilation Via latexmk"; package = mkOption { type = package; From 6a80573475e4ce02b942250da92840fba8eac995 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 19:55:48 -0700 Subject: [PATCH 49/65] Clarified documentation wording and utilized mkPackageOption for the tectonic builder --- .../languages/tex/build/builders/tectonic.nix | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 315b13de..b9b4e656 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -11,8 +11,8 @@ template = import ./builderTemplate.nix; inherit (lib) optionals; - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) enum ints listOf package str; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) enum ints listOf str; inherit (lib.nvim.config) mkBool; inherit (builtins) concatLists elem map toString; @@ -24,11 +24,7 @@ in ( options = { enable = mkEnableOption "Tex Compilation Via Tectonic"; - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; + package = mkPackageOption pkgs "tectonic" {}; executable = mkOption { type = str; @@ -38,18 +34,18 @@ in ( # -- Flags -- keepIntermediates = mkBool false '' - Keep the intermediate files generated during processing. + Whether to keep the intermediate files generated during processing. If texlab is reporting build errors when there shouldn't be, disable this option. ''; keepLogs = mkBool true '' - Keep the log files generated during processing. + Whether to keep the log files generated during processing. Without the keepLogs flag, texlab won't be able to report compilation warnings. ''; - onlyCached = mkBool false "Use only resource files cached locally"; - synctex = mkBool true "Generate SyncTeX data"; - untrustedInput = mkBool false "Input is untrusted -- disable all known-insecure features"; + onlyCached = mkBool false "Whether to use only resource files cached locally"; + synctex = mkBool true "Whether to generate SyncTeX data"; + untrustedInput = mkBool false "Whether to input is untrusted -- disable all known-insecure features"; # -- Options -- reruns = mkOption { @@ -57,7 +53,9 @@ in ( default = 0; example = 2; description = '' - Rerun the TeX engine exactly this many times after the first. + How many times to *rerun* the TeX build engine. + The build engine (if a builder is enabled) will always run at least + once. Setting this value to 0 will disable setting this option. ''; From 123027e48e198b6de097c428671e896ad8ee1c9e Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 20:48:34 -0700 Subject: [PATCH 50/65] Created assertion for the correct number of pdf viewers instead of throwing an error. --- .../languages/tex/pdfViewer/default.nix | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix index 43a16907..18d5bd58 100644 --- a/modules/plugins/languages/tex/pdfViewer/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -5,9 +5,10 @@ }: let defaultPdfViewerName = "okular"; + inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; + inherit (lib.modules) mkIf; inherit (lib.options) mkOption; inherit (lib.types) str package listOf; - inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; cfg = config.vim.languages.tex; viewerCfg = cfg.pdfViewer; @@ -44,14 +45,11 @@ # Get the index that will be used for the next iteration nextIndex = index + 1; - # Increment the count that is recording the number of enabled pdf viewers if - # this viewer is enabled, otherwise leave it as is. + # Increment the count that is recording the number of enabled pdf viewers + # if this viewer is enabled, otherwise leave it as is. newEnabledPdfViewersCount = if currentPdfViewer.enable - then - if enabledPdfViewersCount > 0 - then throw "nvf-tex-language does not support having more than 1 pdf viewer enabled!" - else enabledPdfViewersCount + 1 + then enabledPdfViewersCount + 1 else enabledPdfViewersCount; # If this pdf viewer is enabled, set is as the enabled viewer. @@ -84,8 +82,8 @@ in { imports = [ ./custom.nix ./okular.nix - ./sioyek.nix ./qpdfview.nix + ./sioyek.nix ./zathura.nix ]; @@ -96,10 +94,12 @@ in { description = '' The name of the pdf viewer to use. - This value will be automatically set when any of the viewers are enabled. + This value will be automatically set when any of the viewers are + enabled. - Setting this option option manually is not recommended but can be used for some very technical nix-ing. - If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. + Setting this option option manually is not recommended but can be used + for some very technical nix-ing. If you wish to use a custom viewer, + please use the `custom` entry provided under `viewers`. ''; }; @@ -109,10 +109,12 @@ in { description = '' The package of the pdf viewer to use. - This value will be automatically set when any of the viewers are enabled. + This value will be automatically set when any of the viewers are + enabled. - Setting this option option manually is not recommended but can be used for some very technical nix-ing. - If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. + Setting this option option manually is not recommended but can be used + for some very technical nix-ing. If you wish to use a custom viewer, + please use the `custom` entry provided under `viewers`. ''; }; @@ -122,10 +124,12 @@ in { description = '' The executable for the pdf viewer to use. - This value will be automatically set when any of the viewers are enabled. + This value will be automatically set when any of the viewers are + enabled. - Setting this option option manually is not recommended but can be used for some very technical nix-ing. - If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. + Setting this option option manually is not recommended but can be used + for some very technical nix-ing. If you wish to use a custom viewer, + please use the `custom` entry provided under `viewers`. ''; }; @@ -135,11 +139,25 @@ in { description = '' The command line arguments to use when calling the pdf viewer command. - This value will be automatically set when any of the viewers are enabled. + This value will be automatically set when any of the viewers are + enabled. - Setting this option option manually is not recommended but can be used for some very technical nix-ing. - If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`. + Setting this option option manually is not recommended but can be used + for some very technical nix-ing. If you wish to use a custom viewer, + please use the `custom` entry provided under `viewers`. ''; }; }; + + config = mkIf (enabledPdfViewersInfo.count > 0) { + assertions = [ + { + assertion = enabledPdfViewersInfo.count < 2; + message = '' + The nvf-tex-language implementation does not support having more than + 1 pdf viewers enabled. + ''; + } + ]; + }; } From e640feff1a6ef28ef0d39f35556c884a8067d329 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 21:14:24 -0700 Subject: [PATCH 51/65] Cleaned up documentation and other performed other code cleanups --- .../languages/tex/build/builders/default.nix | 3 +- .../languages/tex/build/builders/latexmk.nix | 5 +- .../languages/tex/build/builders/tectonic.nix | 88 ++++--- .../plugins/languages/tex/build/default.nix | 69 +++-- modules/plugins/languages/tex/default.nix | 61 +++-- modules/plugins/languages/tex/lsp/texlab.nix | 243 ++++++++++++------ .../languages/tex/pdfViewer/custom.nix | 15 +- .../languages/tex/pdfViewer/okular.nix | 15 +- .../languages/tex/pdfViewer/qpdfview.nix | 15 +- .../languages/tex/pdfViewer/sioyek.nix | 18 +- .../tex/pdfViewer/viewerTemplate.nix | 3 +- .../languages/tex/pdfViewer/zathura.nix | 16 +- modules/plugins/languages/tex/treesitter.nix | 5 - 13 files changed, 343 insertions(+), 213 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/default.nix b/modules/plugins/languages/tex/build/builders/default.nix index 4586b768..fa51e70a 100644 --- a/modules/plugins/languages/tex/build/builders/default.nix +++ b/modules/plugins/languages/tex/build/builders/default.nix @@ -6,8 +6,7 @@ }: let inherit (lib.options) mkOption; inherit (lib.types) enum listOf package str; - inherit (lib.nvim.config) mkBool; - inherit (builtins) attrNames filter isAttrs hasAttr elemAt length; + inherit (builtins) attrNames; cfg = config.vim.languages.tex; in { diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index 9037fd6a..8872f3dd 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -29,7 +29,10 @@ in ( executable = mkOption { type = str; default = "latexmk"; - description = "The executable name from the build package that will be used to build/compile the tex."; + description = '' + The executable name from the build package that will be used to + build/compile the tex. + ''; }; # Flag options diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index b9b4e656..ed1e8edb 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -12,7 +12,7 @@ inherit (lib) optionals; inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) enum ints listOf str; + inherit (lib.types) enum ints listOf str nullOr; inherit (lib.nvim.config) mkBool; inherit (builtins) concatLists elem map toString; @@ -29,23 +29,32 @@ in ( executable = mkOption { type = str; default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; + description = '' + The executable name from the build package that will be used to + build/compile the tex. + ''; }; # -- Flags -- keepIntermediates = mkBool false '' Whether to keep the intermediate files generated during processing. - If texlab is reporting build errors when there shouldn't be, disable this option. + If texlab is reporting build errors when there shouldn't be, disable + this option. ''; keepLogs = mkBool true '' Whether to keep the log files generated during processing. - Without the keepLogs flag, texlab won't be able to report compilation warnings. + Without the keepLogs flag, texlab won't be able to report compilation + warnings. + ''; + onlyCached = mkBool false '' + Whether to use only resource files cached locally ''; - onlyCached = mkBool false "Whether to use only resource files cached locally"; synctex = mkBool true "Whether to generate SyncTeX data"; - untrustedInput = mkBool false "Whether to input is untrusted -- disable all known-insecure features"; + untrustedInput = mkBool false '' + Whether to diable all known-insecure features if the input is untrusted + ''; # -- Options -- reruns = mkOption { @@ -62,28 +71,37 @@ in ( }; bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + type = nullOr str; + default = null; + description = '' + Use this directory or Zip-format bundle file to find resource files + instead of the default. + ''; }; webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; + type = nullOr str; + default = null; + description = '' + Use this URL to find resource files instead of the default. + ''; }; outfmt = mkOption { - type = enum [ + type = nullOr (enum [ "pdf" "html" "xdv" "aux" "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; + ]); + default = null; + description = '' + The kind of output to generate. + + Setting this to `null` (default) will let tectonic decide the most + appropriate output format, which usually be a pdf. + ''; }; hidePaths = mkOption { @@ -93,23 +111,27 @@ in ( "./secrets.tex" "./passwords.tex" ]; - description = "Tell the engine that no file at exists, if it tries to read it."; + description = '' + Tell the engine that no file at `` exists, if it tries + to read it. + ''; }; format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; + type = nullOr str; + default = null; + description = '' + The name of the \"format\" file used to initialize the TeX engine. + ''; }; color = mkOption { - type = enum [ + type = nullOr (enum [ "always" "auto" "never" - "" - ]; - default = ""; + ]); + default = null; example = "always"; description = "Enable/disable colorful log output"; }; @@ -118,8 +140,10 @@ in ( type = listOf str; default = []; description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. + Add extra command line options to include in the tectonic build + command. + Extra options added here will not overwrite the options set in as nvf + options. ''; }; }; @@ -139,12 +163,12 @@ in ( ++ (optionals builderCfg.untrustedInput ["--untrusted"]) # Options ++ (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}"]) + ++ (optionals (builderCfg.bundle != null) ["--bundle" "${toString builderCfg.bundle}"]) + ++ (optionals (builderCfg.webBundle != null) ["--web-bundle" "${toString builderCfg.webBundle}"]) + ++ (optionals (builderCfg.outfmt != null) ["--outfmt" "${toString builderCfg.outfmt}"]) ++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths)) - ++ (optionals (builderCfg.format != "") ["--format" "${toString builderCfg.format}"]) - ++ (optionals (builderCfg.color != "") ["--color" "${toString builderCfg.color}"]) + ++ (optionals (builderCfg.format != null) ["--format" "${toString builderCfg.format}"]) + ++ (optionals (builderCfg.color != null) ["--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 diff --git a/modules/plugins/languages/tex/build/default.nix b/modules/plugins/languages/tex/build/default.nix index 3daa0ea7..9f9c5bc3 100644 --- a/modules/plugins/languages/tex/build/default.nix +++ b/modules/plugins/languages/tex/build/default.nix @@ -3,11 +3,11 @@ lib, ... }: let - inherit (lib.options) mkOption; - inherit (lib.modules) mkIf; - inherit (lib.types) str nullOr; inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; + inherit (lib.modules) mkIf; inherit (lib.nvim.config) mkBool; + inherit (lib.options) mkOption; + inherit (lib.types) str nullOr; cfg = config.vim.languages.tex; @@ -48,20 +48,28 @@ in { ]; options.vim.languages.tex.build = { - enable = - mkBool (enabledBuildersCount == 1) '' - Whether to enable configuring the builder. + enable = mkBool (enabledBuildersCount == 1) '' + Whether to enable configuring the builder. - By enabling any of the builders, this option will be automatically set. - If you enable more than one builder then an error will be thrown. - ''; + By enabling any of the builders, this option will be automatically set. + If you enable more than one builder then an error will be thrown. + ''; - forwardSearchAfter = mkBool false "Set this property to true if you want to execute a forward search after a build."; + forwardSearchAfter = mkBool false '' + Set this property to `true` if you want to execute a forward search after + a build. - onSave = mkBool false "Set this property to true if you want to compile the project after saving a file."; + This can also be thought of as enabling auto updating for your pdf viewer. + ''; + + onSave = mkBool false '' + Set this property to `true` if you want to compile the project after + saving a file. + ''; useFileList = mkBool false '' - When set to `true`, the server will use the `.fls` files produced by the TeX engine as an additional input for the project detection. + When set to `true`, the server will use the `.fls` files produced by the + TeX engine as an additional input for the project detection. Note that enabling this property might have an impact on performance. ''; @@ -70,10 +78,12 @@ in { type = str; default = "."; description = '' - When not using latexmk, provides a way to define the directory containing the .aux files. - Note that you need to set the aux directory in latex.build.args too. + When not using latexmk, provides a way to define the directory + containing the `.aux` files. + Note that you need to set the aux directory in `latex.build.args` too. - When using a latexmkrc file, texlab will automatically infer the correct setting. + When using a latexmkrc file, texlab will automatically infer the correct + setting. ''; }; @@ -81,10 +91,13 @@ in { type = str; default = "."; description = '' - When not using latexmk, provides a way to define the directory containing the build log files. - Note that you need to change the output directory in your build arguments too. + When not using latexmk, provides a way to define the directory + containing the build log files. + Note that you need to change the output directory in your build + arguments too. - When using a latexmkrc file, texlab will automatically infer the correct setting. + When using a latexmkrc file, texlab will automatically infer the correct + setting. ''; }; @@ -92,10 +105,13 @@ in { type = str; default = "."; description = '' - When not using latexmk, provides a way to define the directory containing the output files. - Note that you need to set the output directory in latex.build.args too. + When not using latexmk, provides a way to define the directory + containing the output files. + Note that you need to set the output directory in `latex.build.args` + too. - When using a latexmkrc file, texlab will automatically infer the correct setting. + When using a latexmkrc file, texlab will automatically infer the correct + setting. ''; }; @@ -104,17 +120,20 @@ in { 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. + 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."; + assertion = enabledBuildersCount < 2; + message = '' + The nvf-tex-language implementation does not support having more than + 1 builders enabled. + ''; } ]; }; diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index be77a49e..e427f8a3 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -4,16 +4,17 @@ ... }: let inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.config) mkBool; inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) bool str; + inherit (lib.types) enum; cfg = config.vim.languages.tex; in { imports = [ - ./treesitter.nix - ./lsp ./build + ./lsp ./pdfViewer + ./treesitter.nix ]; options.vim.languages.tex = { @@ -21,38 +22,46 @@ in { extraOpts = { texFlavor = { - enable = mkOption { - type = bool; - default = false; - example = true; - description = '' - Whether to set the `vim.g.tex_flavor` (`g:tex_flavor`) option in your Lua config. + enable = mkBool false '' + Whether to set the `vim.g.tex_flavor` (`g:tex_flavor`) option in + your Lua config. - When opening a .tex file vim will try to automatically try to determine the file type from - the three options: plaintex (for plain TeX), context (for ConTeXt), or tex (for LaTeX). - This can either be done by a indicator line of the form `%&` on the first line or - if absent vim will search the file for keywords to try and determine the filetype. - If no filetype can be determined automatically then by default it will fallback to plaintex. + When opening a `.tex` file vim will try to automatically try to + determine the file type from the three options: `plaintex` (for + plain TeX), `context` (for ConTeXt), or `tex` (for LaTeX). + This can either be done by a indicator line of the form `%&` + on the first line or, if absent, vim will search the file for + keywords to try and determine the filetype. If no filetype can be + determined automatically then by default it will fallback to + plaintex. - This option will enable setting the tex flavor in your lua config and you can set its value - using the `vim.languages.tex.lsp.extraOpts.texFlavor.flavor = ` in your nvf config. + This option will enable setting the tex flavor in your lua config + and you can set its value using the + `vim.languages.tex.lsp.extraOpts.texFlavor.flavor = ` in + your nvf config. - Setting this option to `false` will omit the `vim.g.tex_flavor = ` line from your lua - config entirely (unless you manually set it elsewhere of course). - ''; - }; + Setting this option to `false` will omit the + `vim.g.tex_flavor = ` line from your lua config entirely + (unless you manually set it elsewhere of course). + ''; flavor = mkOption { - type = str; + type = enum [ + "plaintex" + "contex" + "tex" + ]; default = "plaintex"; example = "tex"; description = '' - The flavor to set as a fallback for when vim cannot automatically determine the tex flavor when - opening a .tex document. + The flavor to set as a fallback for when vim cannot automatically + determine the tex flavor when opening a `.tex` document. - The options are: plaintex (for plain TeX), context (for ConTeXt), or tex (for LaTeX). + The options are: `plaintex` (for plain TeX), `context` (for + ConTeXt), or `tex` (for LaTeX). - This can be particularly useful for when using `vim.utility.new-file-template` options for - creating templates when no context has yet been added to a new file. + This can be particularly useful for when using + `vim.utility.new-file-template` options for creating templates when + no context has yet been added to a new file. ''; }; }; diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 5677d958..07c64aab 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -4,24 +4,34 @@ lib, ... }: let - inherit (lib.options) mkOption; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) attrs either enum ints listOf nullOr package path str submodule; - inherit (lib.nvim.config) mkBool; inherit (builtins) isString map; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.config) mkBool; + inherit (lib.options) mkOption mkPackageOption; + inherit + (lib.types) + attrs + either + enum + ints + listOf + nullOr + package + path + str + submodule + ; cfg = config.vim.languages.tex; texlabCfg = cfg.lsp.texlab; builderCfg = cfg.build.builder; in { options.vim.languages.tex.lsp.texlab = { - enable = mkBool config.vim.languages.enableLSP "Whether to enable Tex LSP support (texlab)"; + enable = mkBool config.vim.languages.enableLSP '' + Whether to enable Tex LSP support (texlab). + ''; - package = mkOption { - type = package; - default = pkgs.texlab; - description = "texlab package"; - }; + package = mkPackageOption pkgs "texlab" {}; chktex = { enable = mkBool false "Whether to enable linting via chktex"; @@ -35,7 +45,9 @@ in { ''; }; - onOpenAndSave = mkBool false "Lint using chktex after opening and saving a file."; + onOpenAndSave = mkBool false '' + Lint using chktex after opening and saving a file. + ''; onEdit = mkBool false "Lint using chktex after editing a file."; @@ -43,7 +55,8 @@ in { type = listOf str; default = []; description = '' - Additional command line arguments that are passed to chktex after editing a file. + Additional command line arguments that are passed to chktex after + editing a file. Don't redefine the `-I` and `-f` flags as they are set by the server. ''; }; @@ -58,11 +71,15 @@ in { ]; default = "fuzzy-ignore-case"; description = '' - Modifies the algorithm used to filter the completion items returned to the client. Possibles values are: - - fuzzy: Fuzzy string matching (case sensitive) - - fuzzy-ignore-case: Fuzzy string matching (case insensitive) - - prefix: Filter out items that do not start with the search text (case sensitive) - - prefix-ignore-case: Filter out items that do not start with the search text (case insensitive) + Modifies the algorithm used to filter the completion items returned to + the client. + Possibles values are: + - `fuzzy`: Fuzzy string matching (case sensitive). + - `fuzzy-ignore-case`: Fuzzy string matching (case insensitive). + - `prefix`: Filter out items that do not start with the search text + (case sensitive). + - `prefix-ignore-case`: Filter out items that do not start with the + search text (case insensitive). ''; }; @@ -77,13 +94,16 @@ in { type = listOf str; default = []; description = '' - A list of regular expressions used to filter the list of reported diagnostics. - If specified, only diagnostics that match at least one of the specified patterns are sent to the client. + A list of regular expressions used to filter the list of reported + diagnostics. + If specified, only diagnostics that match at least one of the + specified patterns are sent to the client. - See also texlab.diagnostics.ignoredPatterns. + See also `texlab.diagnostics.ignoredPatterns`. - Hint: If both allowedPatterns and ignoredPatterns are set, then allowed patterns are applied first. - Afterwards, the results are filtered with the ignored patterns. + Hint: If both allowedPatterns and ignoredPatterns are set, then + allowed patterns are applied first. Afterwards, the results are + filtered with the ignored patterns. ''; }; @@ -91,35 +111,48 @@ in { type = listOf str; default = []; description = '' - A list of regular expressions used to filter the list of reported diagnostics. - If specified, only diagnostics that match none of the specified patterns are sent to the client. + A list of regular expressions used to filter the list of reported + diagnostics. + If specified, only diagnostics that match none of the specified + patterns are sent to the client. - See also texlab.diagnostics.allowedPatterns. + See also `texlab.diagnostics.allowedPatterns`. ''; }; }; experimental = { - followPackageLinks = mkBool false "If set to true, dependencies of custom packages are resolved and included in the dependency graph."; + followPackageLinks = mkBool false '' + If set to `true`, dependencies of custom packages are resolved and + included in the dependency graph. + ''; mathEnvironments = mkOption { type = listOf str; default = []; - description = "Allows extending the list of environments which the server considers as math environments (for example `align*` or `equation`)."; + description = '' + Allows extending the list of environments which the server considers + as math environments (for example `align*` or `equation`). + ''; }; enumEnvironments = mkOption { type = listOf str; default = []; - description = "Allows extending the list of environments which the server considers as enumeration environments (for example `enumerate` or `itemize`)."; + description = '' + Allows extending the list of environments which the server considers + as enumeration environments (for example `enumerate` or `itemize`). + ''; }; verbatimEnvironments = mkOption { type = listOf str; default = []; description = '' - Allows extending the list of environments which the server considers as verbatim environments (for example `minted` or `lstlisting`). - This can be used to suppress diagnostics from environments that do not contain LaTeX code. + Allows extending the list of environments which the server considers + as verbatim environments (for example `minted` or `lstlisting`). + This can be used to suppress diagnostics from environments that do + not contain LaTeX code. ''; }; @@ -127,9 +160,11 @@ in { type = listOf str; default = []; description = '' - Allows extending the list of commands which the server considers as citation commands (for example `\cite`). + Allows extending the list of commands which the server considers as + citation commands (for example `\cite`). - Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + Hint: Additional commands need to be written without a leading `\` + (e.g. `foo` instead of `\foo`). ''; }; @@ -139,7 +174,8 @@ in { description = '' Allows extending the list of `\label`-like commands. - Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + Hint: Additional commands need to be written without a leading `\` + (e.g. `foo` instead of `\foo`). ''; }; @@ -149,7 +185,8 @@ in { description = '' Allows extending the list of `\ref`-like commands. - Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + Hint: Additional commands need to be written without a leading `\` + (e.g. `foo` instead of `\foo`). ''; }; @@ -159,7 +196,8 @@ in { description = '' Allows extending the list of `\crefrange`-like commands. - Hint: Additional commands need to be written without a leading `\` (e. g. `foo` instead of `\foo`). + Hint: Additional commands need to be written without a leading `\` + (e.g. `foo` instead of `\foo`). ''; }; @@ -167,13 +205,16 @@ in { type = listOf (listOf str); default = []; description = '' - Allows associating a label definition command with a custom prefix. Consider, + Allows associating a label definition command with a custom prefix. + Consider, ``` \newcommand{\theorem}[1]{\label{theorem:#1}} \theorem{foo} ``` - Then setting `texlab.experimental.labelDefinitionPrefixes` to `[["theorem", "theorem:"]]` and adding "theorem" - to `texlab.experimental.labelDefinitionCommands` will make the server recognize the `theorem:foo` label. + Then setting `texlab.experimental.labelDefinitionPrefixes` to + `[["theorem", "theorem:"]]` and adding `theorem` to + `texlab.experimental.labelDefinitionCommands` will make the server + recognize the `theorem:foo` label. ''; }; @@ -195,7 +236,8 @@ in { baz = 314; }; description = '' - For any options that do not have options provided through nvf this can be used to add them. + For any options that do not have options provided through nvf this can + be used to add them. Options already declared in nvf config will NOT be overridden. Options will be placed in: @@ -218,10 +260,12 @@ in { enable = mkBool false '' Whether to enable forward search. - Enable this option if you want to have the compiled document appear in your chosen PDF viewer. + Enable this option if you want to have the compiled document appear in + your chosen PDF viewer. For some options see [here](https://github.com/latex-lsp/texlab/wiki/Previewing). - Note this is not all the options, but can act as a guide to help you along with custom configs. + Note this is not all the options, but can act as a guide to help you + along with custom configs. ''; package = mkOption { @@ -239,7 +283,8 @@ in { type = str; default = cfg.pdfViewer.executable; description = '' - Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. + Defines the executable of the PDF previewer. The previewer needs to + support SyncTeX. By default it is set to the executable of the pdfViewer option. ''; @@ -249,28 +294,37 @@ in { type = listOf str; default = cfg.pdfViewer.args; description = '' - Defines additional arguments that are passed to the configured previewer to perform the forward search. - The placeholders %f, %p, %l will be replaced by the server. + Defines additional arguments that are passed to the configured + previewer to perform the forward search. + The placeholders `%f`, `%p`, `%l` will be replaced by the server. By default it is set to the args of the pdfViewer option. Placeholders: - - %f: The path of the current TeX file. - - %p: The path of the current PDF file. - - %l: The current line number. + - `%f`: The path of the current TeX file. + - `%p`: The path of the current PDF file. + - `%l`: The current line number. ''; }; }; formatter = { formatterLineLength = mkOption { - type = ints.positive; + type = ints.unsigned; default = 80; - description = "Defines the maximum amount of characters per line (0 = disable) when formatting BibTeX files."; + description = '' + Defines the maximum amount of characters per line when formatting + BibTeX files. + + Setting this value to 0 will disable this option. + ''; }; bibtexFormatter = mkOption { - type = enum ["texlab" "latexindent"]; + type = enum [ + "texlab" + "latexindent" + ]; default = "texlab"; description = '' Defines the formatter to use for BibTeX formatting. @@ -279,7 +333,10 @@ in { }; latexFormatter = mkOption { - type = enum ["texlab" "latexindent"]; + type = enum [ + "texlab" + "latexindent" + ]; default = "latexindent"; description = '' Defines the formatter to use for LaTeX formatting. @@ -290,14 +347,23 @@ in { }; inlayHints = { - labelDefinitions = mkBool true "When enabled, the server will return inlay hints for `\\label`-like commands."; + labelDefinitions = mkBool true '' + When enabled, the server will return inlay hints for `\label`-like + commands. + ''; - labelReferences = mkBool true "When enabled, the server will return inlay hints for `\\ref``-like commands."; + labelReferences = mkBool true '' + When enabled, the server will return inlay hints for `\ref`-like + commands. + ''; maxLength = mkOption { type = nullOr ints.positive; default = null; - description = "When set, the server will truncate the text of the inlay hints to the specified length."; + description = '' + When set, the server will truncate the text of the inlay hints to the + specified length. + ''; }; }; @@ -307,25 +373,33 @@ in { default = null; description = '' Defines the path of a file containing the latexindent configuration. - This corresponds to the --local=file.yaml flag of latexindent. - By default the configuration inside the project root directory is used. + This corresponds to the `--local=file.yaml` flag of latexindent. + By default the configuration inside the project root directory is + used. ''; }; modifyLineBreaks = mkBool false '' - Modifies linebreaks before, during, and at the end of code blocks when formatting with latexindent. - This corresponds to the --modifylinebreaks flag of latexindent. + Modifies linebreaks before, during, and at the end of code blocks when + formatting with latexindent. + This corresponds to the `--modifylinebreaks` flag of latexindent. ''; replacement = mkOption { - type = nullOr (enum ["-r" "-rv" "-rr"]); + type = nullOr (enum [ + "-r" + "-rv" + "-rr" + ]); default = null; description = '' - Defines an additional replacement flag that is added when calling latexindent. This can be one of the following: - - "-r" - - "-rv" - - "-rr" - - null + Defines an additional replacement flag that is added when calling + latexindent. + This can be one of the following: + - `-r` + - `-rv` + - `-rr` + - `null` By default no replacement flag is passed. ''; }; @@ -338,15 +412,18 @@ in { type = listOf str; default = []; description = '' - A list of regular expressions used to filter the list of reported document symbols. - If specified, only symbols that match at least one of the specified patterns are sent to the client. - Symbols are filtered recursively so nested symbols can still be sent to the client even though the - parent node is removed from the results. + A list of regular expressions used to filter the list of reported + document symbols. + If specified, only symbols that match at least one of the specified + patterns are sent to the client. + Symbols are filtered recursively so nested symbols can still be sent + to the client even though the parent node is removed from the results. See also `texlab.symbols.ignoredPatterns`. - Hint: If both allowedPatterns and ignoredPatterns are set, then allowed patterns are applied first. - Afterwards, the results are filtered with the ignored patterns. + Hint: If both `allowedPatterns` and `ignoredPatterns` are set, then + allowed patterns are applied first. Afterwards, the results are + filtered with the ignored patterns. ''; }; @@ -354,8 +431,10 @@ in { type = listOf str; default = []; description = '' - A list of regular expressions used to filter the list of reported document symbols. - If specified, only symbols that match none of the specified patterns are sent to the client. + A list of regular expressions used to filter the list of reported + document symbols. + If specified, only symbols that match none of the specified patterns + are sent to the client. See also `texlab.symbols.allowedPatterns`. ''; @@ -371,10 +450,14 @@ in { displayName = mkOption { type = nullOr str; default = null; - description = "The name shown in the document symbols. Defaults to the value of `name`."; + description = '' + The name shown in the document symbols. + Defaults to the value of `name`. + ''; }; label = mkBool false '' - If set, the server will try to match a label to environment and append its number. + If set to `true`, the server will try to match a label to + environment and append its number. ''; }; }); @@ -387,9 +470,10 @@ in { } ]; description = '' - A list of objects that allows extending the list of environments that are part of the document symbols. + A list of objects that allows extending the list of environments that + are part of the document symbols. - See also texlab.symbols.allowedPatterns. + See also `texlab.symbols.allowedPatterns`. Type: listOf submodule: - name: @@ -402,11 +486,12 @@ in { - default: - label: - type: boolean - - description: If set, the server will try to match a label to environment and append its number. + - description: If set, the server will try to match a label to + environment and append its number. - default: false - Note: This functionality may not be working, please follow https://github.com/latex-lsp/texlab/pull/1311 - for status updates. + Note: This functionality may not be working, please follow + https://github.com/latex-lsp/texlab/pull/1311 for status updates. ''; }; }; diff --git a/modules/plugins/languages/tex/pdfViewer/custom.nix b/modules/plugins/languages/tex/pdfViewer/custom.nix index 189663fe..7b8a9de4 100644 --- a/modules/plugins/languages/tex/pdfViewer/custom.nix +++ b/modules/plugins/languages/tex/pdfViewer/custom.nix @@ -9,8 +9,8 @@ # The viewer template template = import ./viewerTemplate.nix; - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) package str listOf; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) str listOf; in ( template { inherit name moduleInheritancePackage; @@ -18,10 +18,8 @@ in ( options = { enable = mkEnableOption "enable using a custom pdf viewer."; - package = mkOption { - type = package; - example = pkgs.okular; - description = "custom viewer package"; + package = mkPackageOption pkgs "okular" { + extraDescription = "custom viewer package"; }; executable = mkOption { @@ -32,7 +30,10 @@ in ( args = mkOption { type = listOf str; - example = ["--unique" "file:%p#src:%l%f"]; + example = [ + "--unique" + "file:%p#src:%l%f" + ]; description = "Arguments to pass to the viewer."; }; }; diff --git a/modules/plugins/languages/tex/pdfViewer/okular.nix b/modules/plugins/languages/tex/pdfViewer/okular.nix index e341fa4d..0c3d7f8d 100644 --- a/modules/plugins/languages/tex/pdfViewer/okular.nix +++ b/modules/plugins/languages/tex/pdfViewer/okular.nix @@ -9,8 +9,8 @@ # The viewer template template = import ./viewerTemplate.nix; - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) package str listOf; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) str listOf; in ( template { inherit name moduleInheritancePackage; @@ -18,11 +18,7 @@ in ( options = { enable = mkEnableOption "enable okular as the pdf file previewer."; - package = mkOption { - type = package; - default = pkgs.okular; - description = "okular package"; - }; + package = mkPackageOption pkgs "okular" {}; executable = mkOption { type = str; @@ -32,7 +28,10 @@ in ( args = mkOption { type = listOf str; - default = ["--unique" "file:%p#src:%l%f"]; + default = [ + "--unique" + "file:%p#src:%l%f" + ]; description = "Arguments to pass to the viewer."; }; }; diff --git a/modules/plugins/languages/tex/pdfViewer/qpdfview.nix b/modules/plugins/languages/tex/pdfViewer/qpdfview.nix index ef294bcf..1938fb94 100644 --- a/modules/plugins/languages/tex/pdfViewer/qpdfview.nix +++ b/modules/plugins/languages/tex/pdfViewer/qpdfview.nix @@ -9,8 +9,8 @@ # The viewer template template = import ./viewerTemplate.nix; - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) package str listOf; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) str listOf; in ( template { inherit name moduleInheritancePackage; @@ -18,11 +18,7 @@ in ( options = { enable = mkEnableOption "enable qpdfview as the pdf file previewer."; - package = mkOption { - type = package; - default = pkgs.qpdfview; - description = "qpdfview package"; - }; + package = mkPackageOption pkgs "qpdfview" {}; executable = mkOption { type = str; @@ -32,7 +28,10 @@ in ( args = mkOption { type = listOf str; - default = ["--unique" "%p#src:%f:%l:1"]; + default = [ + "--unique" + "%p#src:%f:%l:1" + ]; description = "Arguments to pass to the viewer."; }; }; diff --git a/modules/plugins/languages/tex/pdfViewer/sioyek.nix b/modules/plugins/languages/tex/pdfViewer/sioyek.nix index a4c647b1..ad0b4943 100644 --- a/modules/plugins/languages/tex/pdfViewer/sioyek.nix +++ b/modules/plugins/languages/tex/pdfViewer/sioyek.nix @@ -9,20 +9,16 @@ # The viewer template template = import ./viewerTemplate.nix; - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) package str listOf; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) str listOf; in ( template { inherit name moduleInheritancePackage; options = { - enable = mkEnableOption "enable sioyek as the pdf file previewer."; + enable = mkEnableOption "sioyek as the pdf file previewer."; - package = mkOption { - type = package; - default = pkgs.sioyek; - description = "sioyek package"; - }; + package = mkPackageOption pkgs "sioyek" {}; executable = mkOption { type = str; @@ -47,9 +43,9 @@ in ( description = '' Arguments to pass to the viewer. - By default, this is the only viewer that supports the inverse search feature by - command line arguments and doesn't explicitly require extra tinkering else where - in your config. + By default, this is the only viewer that supports the inverse search + feature by command line arguments and doesn't explicitly require extra + tinkering else where in your config. ''; }; }; diff --git a/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix index dd81b7a4..72c52877 100644 --- a/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix +++ b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix @@ -56,7 +56,8 @@ in { opts) options; - # Check that the language and this pdf viewer have been enabled before making any config. + # Check that the language and this pdf viewer have been enabled before making + # any config. config = mkIf (cfg.enable && viewerCfg.enable) { vim.languages.tex.pdfViewer = { inherit name; diff --git a/modules/plugins/languages/tex/pdfViewer/zathura.nix b/modules/plugins/languages/tex/pdfViewer/zathura.nix index 99d95498..f1fd16d5 100644 --- a/modules/plugins/languages/tex/pdfViewer/zathura.nix +++ b/modules/plugins/languages/tex/pdfViewer/zathura.nix @@ -9,8 +9,8 @@ # The viewer template template = import ./viewerTemplate.nix; - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) package str listOf; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) str listOf; in ( template { inherit name moduleInheritancePackage; @@ -18,11 +18,7 @@ in ( options = { enable = mkEnableOption "enable zathura as the pdf file previewer."; - package = mkOption { - type = package; - default = pkgs.zathura; - description = "zathura package"; - }; + package = mkPackageOption pkgs "zathura" {}; executable = mkOption { type = str; @@ -32,7 +28,11 @@ in ( args = mkOption { type = listOf str; - default = ["--synctex-forward" "%l:1:%f" "%p"]; + default = [ + "--synctex-forward" + "%l:1:%f" + "%p" + ]; description = "Arguments to pass to the viewer."; }; }; diff --git a/modules/plugins/languages/tex/treesitter.nix b/modules/plugins/languages/tex/treesitter.nix index 98185ba8..fcebaa99 100644 --- a/modules/plugins/languages/tex/treesitter.nix +++ b/modules/plugins/languages/tex/treesitter.nix @@ -4,22 +4,17 @@ lib, ... }: let - # inherit (lib.options) mkEnableOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.types) mkGrammarOption mkEnableTreesitterOption; cfg = config.vim.languages.tex; - - # mkEnableTreesitterOption = description: mkEnableOption description // {default = config.vim.languages.enableTreesitter;}; in { options.vim.languages.tex.treesitter = { latex = { - # enable = mkEnableTreesitterOption "Whether to enable Latex treesitter"; enable = mkEnableTreesitterOption config "latex"; package = mkGrammarOption pkgs "latex"; }; bibtex = { - # enable = mkEnableTreesitterOption "Whether to enable Bibtex treesitter"; enable = mkEnableTreesitterOption config "bibtex"; package = mkGrammarOption pkgs "bibtex"; }; From 2e326bdb689d5646acd718aabb2c604edf782b13 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 21:28:17 -0700 Subject: [PATCH 52/65] Utilized lib.optionalAttrs to simplify code --- modules/plugins/languages/tex/lsp/texlab.nix | 99 +++++++++----------- 1 file changed, 42 insertions(+), 57 deletions(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 07c64aab..963d280a 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -5,6 +5,7 @@ ... }: let inherit (builtins) isString map; + inherit (lib) optionalAttrs; inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.config) mkBool; inherit (lib.options) mkOption mkPackageOption; @@ -529,70 +530,54 @@ in { } # # -- Build -- - // ( - if cfg.build.enable - then { - build = { - inherit - (cfg.build) - onSave - useFileList - auxDirectory - logDirectory - pdfDirectory - filename - forwardSearchAfter - ; - inherit (builderCfg) args; - executable = "${builderCfg.package}/bin/${builderCfg.executable}"; - }; - } - else {} - ) + // (optionalAttrs cfg.build.enable { + build = { + inherit + (cfg.build) + onSave + useFileList + auxDirectory + logDirectory + pdfDirectory + filename + forwardSearchAfter + ; + inherit (builderCfg) args; + executable = "${builderCfg.package}/bin/${builderCfg.executable}"; + }; + }) # # -- Chktex -- - // ( - if texlabCfg.chktex.enable - then { - chktex = { - inherit (texlabCfg.chktex) onOpenAndSave onEdit additionalArgs; - }; - } - else {} - ) + // (optionalAttrs texlabCfg.chktex.enable { + chktex = { + inherit (texlabCfg.chktex) onOpenAndSave onEdit additionalArgs; + }; + }) # # -- Forward Search -- - // ( - if texlabCfg.forwardSearch.enable - then { - forwardSearch = { - inherit (texlabCfg.forwardSearch) args; - executable = "${texlabCfg.forwardSearch.package}/bin/${texlabCfg.forwardSearch.executable}"; - }; - } - else {} - ) + // (optionalAttrs texlabCfg.forwardSearch.enable { + forwardSearch = { + inherit (texlabCfg.forwardSearch) args; + executable = "${texlabCfg.forwardSearch.package}/bin/${texlabCfg.forwardSearch.executable}"; + }; + }) # # -- Symbols -- - // ( - if texlabCfg.symbols.enable - then { - symbols = { - inherit (texlabCfg.symbols) allowedPatterns ignoredPatterns; + // (optionalAttrs texlabCfg.symbols.enable { + symbols = { + inherit (texlabCfg.symbols) allowedPatterns ignoredPatterns; - customEnvironments = - map (x: { - inherit (x) name label; - displayName = - if isString x.displayName - then x.displayName - else x.name; - }) - texlabCfg.symbols.customEnvironments; - }; - } - else {} - ) + customEnvironments = + map (x: { + inherit (x) name label; + displayName = + if isString x.displayName + then x.displayName + else x.name; + }) + texlabCfg.symbols.customEnvironments; + }; + }) # # -- Extra Settings -- // texlabCfg.extraLuaSettings From d6433345f9b77276aef02f870b1057aa1f424e0c Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Tue, 11 Feb 2025 21:30:44 -0700 Subject: [PATCH 53/65] Added comment explaining why code is structured as it is --- modules/plugins/languages/tex/build/builders/latexmk.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index 8872f3dd..bbb4ecd5 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -44,6 +44,8 @@ in ( }; }; + # Optional flags must come before the base args because of how the latexmk + # command works args = builderCfg: ( # Flags (optionals builderCfg.pdfOutput ["-pdf"]) From bd90630606213f70889c35c1425fc5c6e8ae28d6 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Wed, 12 Feb 2025 01:03:07 -0700 Subject: [PATCH 54/65] Cleaned up tectonic args processing --- .../languages/tex/build/builders/tectonic.nix | 105 +++++++++++++----- 1 file changed, 78 insertions(+), 27 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index ed1e8edb..bdacd1e2 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -14,7 +14,14 @@ inherit (lib.options) mkOption mkEnableOption mkPackageOption; inherit (lib.types) enum ints listOf str nullOr; inherit (lib.nvim.config) mkBool; - inherit (builtins) concatLists elem map toString; + inherit (builtins) concatLists elem map toString attrNames filter isList; + + notNull = x: x != null; + forceCheck = x: true; + toList = x: + if isList x + then x + else [x]; cfg = config.vim.languages.tex; in ( @@ -148,31 +155,75 @@ in ( }; }; - args = builderCfg: ( - # Base args - [ - "-X" - "compile" - "%f" - ] - # Flags - ++ (optionals builderCfg.keepIntermediates ["--keep-intermediates"]) - ++ (optionals builderCfg.keepLogs ["--keep-logs"]) - ++ (optionals builderCfg.onlyCached ["--only-cached"]) - ++ (optionals builderCfg.synctex ["--synctex"]) - ++ (optionals builderCfg.untrustedInput ["--untrusted"]) - # Options - ++ (optionals (builderCfg.reruns > 0) ["--reruns" "${toString builderCfg.reruns}"]) - ++ (optionals (builderCfg.bundle != null) ["--bundle" "${toString builderCfg.bundle}"]) - ++ (optionals (builderCfg.webBundle != null) ["--web-bundle" "${toString builderCfg.webBundle}"]) - ++ (optionals (builderCfg.outfmt != null) ["--outfmt" "${toString builderCfg.outfmt}"]) - ++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths)) - ++ (optionals (builderCfg.format != null) ["--format" "${toString builderCfg.format}"]) - ++ (optionals (builderCfg.color != null) ["--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 - ++ (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"]) - ); + # args = builderCfg: ( + # # Base args + # [ + # "-X" + # "compile" + # "%f" + # ] + # # Flags + # ++ (optionals builderCfg.keepIntermediates ["--keep-intermediates"]) + # ++ (optionals builderCfg.keepLogs ["--keep-logs"]) + # ++ (optionals builderCfg.onlyCached ["--only-cached"]) + # ++ (optionals builderCfg.synctex ["--synctex"]) + # ++ (optionals builderCfg.untrustedInput ["--untrusted"]) + # # Options + # ++ (optionals (builderCfg.reruns > 0) ["--reruns" "${toString builderCfg.reruns}"]) + # ++ (optionals (builderCfg.bundle != null) ["--bundle" "${toString builderCfg.bundle}"]) + # ++ (optionals (builderCfg.webBundle != null) ["--web-bundle" "${toString builderCfg.webBundle}"]) + # ++ (optionals (builderCfg.outfmt != null) ["--outfmt" "${toString builderCfg.outfmt}"]) + # ++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths)) + # ++ (optionals (builderCfg.format != null) ["--format" "${toString builderCfg.format}"]) + # ++ (optionals (builderCfg.color != null) ["--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 + # ++ (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"]) + # ); + + args = builderCfg: let + option = setCheck: flag: {inherit setCheck flag;}; + args = { + baseArgs = ["-X" "compile" "%f"]; + + flags = { + keepIntermediates = "--keep-intermediates"; + keepLogs = "--keep-logs"; + onlyCached = "--only-cached"; + synctex = "--synctex"; + untrustedInput = "--untrusted"; + }; + + options = { + reruns = option (x: x > 0) "--reruns"; + bundle = option notNull "--bundle"; + webBundle = option notNull "--web-bundle"; + outfmt = option notNull "--outfmt"; + format = option notNull "--format"; + color = option notNull "--color"; + hidePaths = option forceCheck "--hide"; + }; + + externalOptions = concatLists [ + (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"]) + ]; + }; + + flags = map (flag: args.flags.${flag}) (filter (flag: builderCfg.${flag}) (attrNames args.flags)); + options = let + getOptionFlagsList = opt: + concatLists ( + map + (y: [args.options."${opt}".flag "${toString y}"]) + (toList builderCfg."${opt}") + ); + processOption = opt: + optionals + (args.options."${opt}".setCheck builderCfg."${opt}") + (getOptionFlagsList opt); + in (concatLists (map processOption (attrNames args.options))); + in + concatLists (with args; [baseArgs flags options externalOptions]); } ) From 127523101f8b773cf1382b68b1f654d25ccc904e Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Wed, 12 Feb 2025 01:07:42 -0700 Subject: [PATCH 55/65] Reword doc description --- modules/plugins/languages/tex/build/builders/tectonic.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index bdacd1e2..fb0a187d 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -81,8 +81,8 @@ in ( type = nullOr str; default = null; description = '' - Use this directory or Zip-format bundle file to find resource files - instead of the default. + The directory or Zip-format bundle file to find resource files instead + of the default. ''; }; From af04becc50dda7218363aedbbd3af4485f1d1b14 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Wed, 12 Feb 2025 01:17:32 -0700 Subject: [PATCH 56/65] Altered mkEnableTreesitterOption functionallity to take in a boolean instead of all of config --- lib/types/languages.nix | 4 ++-- modules/plugins/languages/tex/treesitter.nix | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/types/languages.nix b/lib/types/languages.nix index 29639047..5e935159 100644 --- a/lib/types/languages.nix +++ b/lib/types/languages.nix @@ -33,10 +33,10 @@ default = ["vimPlugins" "nvim-treesitter" "builtGrammars" grammar]; }; - mkEnableTreesitterOption = config: language: + mkEnableTreesitterOption = defaultCondition: language: mkOption { type = bool; - default = config.vim.languages.enableTreesitter; + default = defaultCondition; description = "Whether to enable ${language} treesitter"; }; in { diff --git a/modules/plugins/languages/tex/treesitter.nix b/modules/plugins/languages/tex/treesitter.nix index fcebaa99..d9c3754b 100644 --- a/modules/plugins/languages/tex/treesitter.nix +++ b/modules/plugins/languages/tex/treesitter.nix @@ -5,17 +5,19 @@ ... }: let inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.types) mkGrammarOption mkEnableTreesitterOption; + inherit (lib.nvim.types) mkGrammarOption; + + mkEnableTreesitterOption = lib.nvim.types.mkEnableTreesitterOption config.vim.languages.enableTreesitter; cfg = config.vim.languages.tex; in { options.vim.languages.tex.treesitter = { latex = { - enable = mkEnableTreesitterOption config "latex"; + enable = mkEnableTreesitterOption "latex"; package = mkGrammarOption pkgs "latex"; }; bibtex = { - enable = mkEnableTreesitterOption config "bibtex"; + enable = mkEnableTreesitterOption "bibtex"; package = mkGrammarOption pkgs "bibtex"; }; }; From 9211746d239502556b30bb2fe19c6f694af0ebd1 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Mon, 17 Feb 2025 17:33:24 -0700 Subject: [PATCH 57/65] Changed the new-file-template-nvim npin to the fork that adds escaping newline characters to support tex templates properly --- npins/sources.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/npins/sources.json b/npins/sources.json index 919ef20d..f88f9289 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -1682,14 +1682,14 @@ "type": "Git", "repository": { "type": "GitHub", - "owner": "otavioschwanck", + "owner": "isaacST08", "repo": "new-file-template.nvim" }, "branch": "master", "submodules": false, - "revision": "6ac66669dbf2dc5cdee184a4fe76d22465ca67e8", - "url": "https://github.com/otavioschwanck/new-file-template.nvim/archive/6ac66669dbf2dc5cdee184a4fe76d22465ca67e8.tar.gz", - "hash": "0c7378c3w6bniclp666rq15c28akb0sjy58ayva0wpyin4k26hl3" + "revision": "dc3a58b1f490c86075c96670b9eb81370c2f2ca1", + "url": "https://github.com/isaacST08/new-file-template.nvim/archive/dc3a58b1f490c86075c96670b9eb81370c2f2ca1.tar.gz", + "hash": "0y6ip3k6bjaf32x1y1p6mmkwwdi71yvwr6klr26m252jrg8352pf" }, "nix-develop-nvim": { "type": "Git", From 3859b8d9c96d890e84620ff05a71347b4b8755a6 Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Fri, 7 Mar 2025 12:19:14 -0700 Subject: [PATCH 58/65] Fixed missing mkOption function call in tectonic.nix --- modules/plugins/languages/tex/build/builders/tectonic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index fb0a187d..13bab492 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -143,7 +143,7 @@ in ( description = "Enable/disable colorful log output"; }; - extraOptions = { + extraOptions = mkOption { type = listOf str; default = []; description = '' From 2393647defacd2346439bb171de9e4defc9116dd Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Fri, 7 Mar 2025 12:29:01 -0700 Subject: [PATCH 59/65] Fixed typo in default.nix --- modules/plugins/languages/tex/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index e427f8a3..7b1df4cd 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -47,7 +47,7 @@ in { flavor = mkOption { type = enum [ "plaintex" - "contex" + "context" "tex" ]; default = "plaintex"; From f57dbd04feff1834cfa19899836d03901e1d712c Mon Sep 17 00:00:00 2001 From: isaacST08 <106057977+isaacST08@users.noreply.github.com> Date: Fri, 7 Mar 2025 12:31:14 -0700 Subject: [PATCH 60/65] Fixed typo in tectonic.nix --- modules/plugins/languages/tex/build/builders/tectonic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 13bab492..6c680cff 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -60,7 +60,7 @@ in ( ''; synctex = mkBool true "Whether to generate SyncTeX data"; untrustedInput = mkBool false '' - Whether to diable all known-insecure features if the input is untrusted + Whether to disable all known-insecure features if the input is untrusted ''; # -- Options -- From d65c4801886ccee2425d1b629426faef0b1c6af2 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Mon, 10 Mar 2025 10:00:26 -0600 Subject: [PATCH 61/65] Started work to resolve infrec error --- .../languages/tex/pdfViewer/default.nix | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix index 18d5bd58..6d6dcd7e 100644 --- a/modules/plugins/languages/tex/pdfViewer/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -5,7 +5,15 @@ }: let defaultPdfViewerName = "okular"; - inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; + inherit + (builtins) + filter + isAttrs + hasAttr + attrNames + length + elemAt + ; inherit (lib.modules) mkIf; inherit (lib.options) mkOption; inherit (lib.types) str package listOf; @@ -24,13 +32,9 @@ pdfViewerNamesList ? ( filter ( x: let - y = viewerCfg.${x}; + y = viewerCfg."${x}"; in ( - isAttrs y - && hasAttr "enable" y - && hasAttr "package" y - && hasAttr "executable" y - && hasAttr "args" y + isAttrs y && hasAttr "enable" y && hasAttr "package" y && hasAttr "executable" y && hasAttr "args" y ) ) (attrNames viewerCfg) ), @@ -40,7 +44,7 @@ currentPdfViewerName = elemAt pdfViewerNamesList index; # Get the current pdf viewer object - currentPdfViewer = viewerCfg.${currentPdfViewerName}; + currentPdfViewer = viewerCfg."${currentPdfViewerName}"; # Get the index that will be used for the next iteration nextIndex = index + 1; @@ -77,7 +81,7 @@ }; in (getEnabledPdfViewersInfo {}); - enabledPdfViewerCfg = viewerCfg.${enabledPdfViewersInfo.enabledViewerName}; + enabledPdfViewerCfg = viewerCfg."${enabledPdfViewersInfo.enabledViewerName}"; in { imports = [ ./custom.nix From 3433bf90711b58809f62258304603a981c3ded83 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 3 May 2025 18:51:58 -0600 Subject: [PATCH 62/65] Refactored pdfViewer and fixed infrec error --- modules/plugins/languages/tex/default.nix | 3 +- modules/plugins/languages/tex/lsp/default.nix | 12 +- modules/plugins/languages/tex/lsp/texlab.nix | 9 +- .../languages/tex/pdfViewer/custom.nix | 43 ---- .../languages/tex/pdfViewer/default.nix | 208 +++++++----------- .../tex/pdfViewer/getEnabledPdfViewer.nix | 22 ++ .../languages/tex/pdfViewer/okular.nix | 41 ---- .../tex/pdfViewer/premadePdfViewers.nix | 80 +++++++ .../languages/tex/pdfViewer/qpdfview.nix | 41 ---- .../languages/tex/pdfViewer/sioyek.nix | 55 ----- .../tex/pdfViewer/viewerTemplate.nix | 68 ------ .../languages/tex/pdfViewer/zathura.nix | 42 ---- 12 files changed, 194 insertions(+), 430 deletions(-) delete mode 100644 modules/plugins/languages/tex/pdfViewer/custom.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/getEnabledPdfViewer.nix delete mode 100644 modules/plugins/languages/tex/pdfViewer/okular.nix create mode 100644 modules/plugins/languages/tex/pdfViewer/premadePdfViewers.nix delete mode 100644 modules/plugins/languages/tex/pdfViewer/qpdfview.nix delete mode 100644 modules/plugins/languages/tex/pdfViewer/sioyek.nix delete mode 100644 modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix delete mode 100644 modules/plugins/languages/tex/pdfViewer/zathura.nix diff --git a/modules/plugins/languages/tex/default.nix b/modules/plugins/languages/tex/default.nix index 7b1df4cd..7dbe7e3a 100644 --- a/modules/plugins/languages/tex/default.nix +++ b/modules/plugins/languages/tex/default.nix @@ -44,6 +44,7 @@ in { `vim.g.tex_flavor = ` line from your lua config entirely (unless you manually set it elsewhere of course). ''; + flavor = mkOption { type = enum [ "plaintex" @@ -71,7 +72,7 @@ in { config = mkIf cfg.enable (mkMerge [ # Extra Lua config options (mkIf cfg.extraOpts.texFlavor.enable { - vim.globals.tex_flavor = "${cfg.extraOpts.texFlavor.flavor}"; + vim.globals.tex_flavor = lib.mkDefault "${cfg.extraOpts.texFlavor.flavor}"; }) ]); } diff --git a/modules/plugins/languages/tex/lsp/default.nix b/modules/plugins/languages/tex/lsp/default.nix index affb272a..244829d0 100644 --- a/modules/plugins/languages/tex/lsp/default.nix +++ b/modules/plugins/languages/tex/lsp/default.nix @@ -12,7 +12,13 @@ in { ./texlab.nix ]; - config = mkIf (cfg.enable && (any (x: x.enable) (attrValues cfg.lsp))) { - vim.lsp.lspconfig.enable = true; # Enable lspconfig when any of the lsps are enabled - }; + config = + mkIf + ( + cfg.enable # Check if nvf is enabled. + && (any (x: x.enable) (attrValues cfg.lsp)) # Check if any of the LSPs have been enabled. + ) + { + vim.lsp.lspconfig.enable = lib.mkDefault true; # Enable lspconfig when any of the lsps are enabled + }; } diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 963d280a..339fb40c 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -26,6 +26,9 @@ cfg = config.vim.languages.tex; texlabCfg = cfg.lsp.texlab; builderCfg = cfg.build.builder; + + # Get the enabled pdf viewer. + pdfViewer = import ../pdfViewer/getEnabledPdfViewer.nix {inherit lib config;}; in { options.vim.languages.tex.lsp.texlab = { enable = mkBool config.vim.languages.enableLSP '' @@ -271,7 +274,7 @@ in { package = mkOption { type = package; - default = cfg.pdfViewer.package; + default = pdfViewer.package; description = '' The package to use as your PDF viewer. This viewer needs to support Synctex. @@ -282,7 +285,7 @@ in { executable = mkOption { type = str; - default = cfg.pdfViewer.executable; + default = pdfViewer.executable; description = '' Defines the executable of the PDF previewer. The previewer needs to support SyncTeX. @@ -293,7 +296,7 @@ in { args = mkOption { type = listOf str; - default = cfg.pdfViewer.args; + default = pdfViewer.args; description = '' Defines additional arguments that are passed to the configured previewer to perform the forward search. diff --git a/modules/plugins/languages/tex/pdfViewer/custom.nix b/modules/plugins/languages/tex/pdfViewer/custom.nix deleted file mode 100644 index 7b8a9de4..00000000 --- a/modules/plugins/languages/tex/pdfViewer/custom.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ - pkgs, - lib, - ... -} @ moduleInheritancePackage: let - # The name of the pdf viewer - name = "custom"; - - # The viewer template - template = import ./viewerTemplate.nix; - - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) str listOf; -in ( - template { - inherit name moduleInheritancePackage; - - options = { - enable = mkEnableOption "enable using a custom pdf viewer."; - - package = mkPackageOption pkgs "okular" { - extraDescription = "custom viewer package"; - }; - - executable = mkOption { - type = str; - example = "okular"; - description = "The executable name to call the viewer."; - }; - - args = mkOption { - type = listOf str; - example = [ - "--unique" - "file:%p#src:%l%f" - ]; - description = "Arguments to pass to the viewer."; - }; - }; - - argsFunction = viewerCfg: (viewerCfg.args); - } -) diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix index 6d6dcd7e..ffa946af 100644 --- a/modules/plugins/languages/tex/pdfViewer/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -1,162 +1,104 @@ { config, lib, + pkgs, ... }: let - defaultPdfViewerName = "okular"; - - inherit - (builtins) - filter - isAttrs - hasAttr - attrNames - length - elemAt - ; - inherit (lib.modules) mkIf; inherit (lib.options) mkOption; inherit (lib.types) str package listOf; cfg = config.vim.languages.tex; - viewerCfg = cfg.pdfViewer; - enabledPdfViewersInfo = let - # This function will sort through the pdf viewer options and count how many - # pdf viewers have been enabled. - # If no viewers have been enabled, the count will be 0 and the name of the - # enabled viewer will be the default pdf viewer defined above. - getEnabledPdfViewersInfo = { - enabledPdfViewersCount ? 0, - index ? 0, - pdfViewerNamesList ? ( - filter ( - x: let - y = viewerCfg."${x}"; - in ( - isAttrs y && hasAttr "enable" y && hasAttr "package" y && hasAttr "executable" y && hasAttr "args" y - ) - ) (attrNames viewerCfg) - ), - currentEnabledPdfViewerName ? defaultPdfViewerName, - }: let - # Get the name of the current pdf viewer being checked if it is enabled - currentPdfViewerName = elemAt pdfViewerNamesList index; + pdfViewer = {name, ...}: { + options = { + enable = lib.mkEnableOption "${builtins.toString name} pdf viewer"; - # Get the current pdf viewer object - currentPdfViewer = viewerCfg."${currentPdfViewerName}"; + name = mkOption { + type = str; + example = "okular"; + description = '' + The name of the pdf viewer to use. - # Get the index that will be used for the next iteration - nextIndex = index + 1; + This value will be automatically set when any of the viewers are + enabled. - # Increment the count that is recording the number of enabled pdf viewers - # if this viewer is enabled, otherwise leave it as is. - newEnabledPdfViewersCount = - if currentPdfViewer.enable - then enabledPdfViewersCount + 1 - else enabledPdfViewersCount; + This value will be automatically set to the value of the parent + attribute set. ex. `...tex.pdfViewer..name = "$${name}"` + This value cannot and should not be changed to be different from this + parent value. - # If this pdf viewer is enabled, set is as the enabled viewer. - newEnabledPdfViewerName = - if currentPdfViewer.enable - then currentPdfViewerName - else currentEnabledPdfViewerName; - in - # Check that the end of the list of viewers has not been reached - if length pdfViewerNamesList > nextIndex - # If the end of the viewers list has not been reached, call the next iteration - # of the function to process the next viewer - then - getEnabledPdfViewersInfo { - inherit pdfViewerNamesList; - enabledPdfViewersCount = newEnabledPdfViewersCount; - index = nextIndex; - currentEnabledPdfViewerName = newEnabledPdfViewerName; - } - # If the end of the viewers list has been reached, then return the total number - # of viewers that have been enabled and the name of the last viewer that was enabled. - else { - count = newEnabledPdfViewersCount; - enabledViewerName = newEnabledPdfViewerName; + Default values already exist such as `...tex.pdfViewer.okular` but + you can override the default values or created completely custom + pdf viewers should you wish. + ''; }; - in (getEnabledPdfViewersInfo {}); - enabledPdfViewerCfg = viewerCfg."${enabledPdfViewersInfo.enabledViewerName}"; + package = mkOption { + type = package; + example = pkgs.kdePackages.okular; + description = "The package of the pdf viewer to use."; + }; + + executable = mkOption { + type = str; + default = "${builtins.toString name}"; + description = '' + The executable for the pdf viewer to use. + + It will be called as `/bin/`. + + By default, the name of the pdf viewer will be used. + ''; + }; + + args = mkOption { + type = listOf str; + default = []; + description = '' + The command line arguments to use when calling the pdf viewer command. + + These will be called as + `/bin/ ...`. + ''; + }; + }; + + # The name of the pdf viewer must be set to the parent attribute set name. + config.name = lib.mkForce name; + }; in { imports = [ - ./custom.nix - ./okular.nix - ./qpdfview.nix - ./sioyek.nix - ./zathura.nix + ./premadePdfViewers.nix ]; - options.vim.languages.tex.pdfViewer = { - name = mkOption { - type = str; - default = enabledPdfViewerCfg.name; - description = '' - The name of the pdf viewer to use. + options.vim.languages.tex.pdfViewer = mkOption { + type = with lib.types; attrsOf (submodule pdfViewer); + default = {}; + example = { + zathura.enable = true; - This value will be automatically set when any of the viewers are - enabled. - - Setting this option option manually is not recommended but can be used - for some very technical nix-ing. If you wish to use a custom viewer, - please use the `custom` entry provided under `viewers`. - ''; - }; - - package = mkOption { - type = package; - default = enabledPdfViewerCfg.package; - description = '' - The package of the pdf viewer to use. - - This value will be automatically set when any of the viewers are - enabled. - - Setting this option option manually is not recommended but can be used - for some very technical nix-ing. If you wish to use a custom viewer, - please use the `custom` entry provided under `viewers`. - ''; - }; - - executable = mkOption { - type = str; - default = enabledPdfViewerCfg.executable; - description = '' - The executable for the pdf viewer to use. - - This value will be automatically set when any of the viewers are - enabled. - - Setting this option option manually is not recommended but can be used - for some very technical nix-ing. If you wish to use a custom viewer, - please use the `custom` entry provided under `viewers`. - ''; - }; - - args = mkOption { - type = listOf str; - default = enabledPdfViewerCfg.args; - description = '' - The command line arguments to use when calling the pdf viewer command. - - This value will be automatically set when any of the viewers are - enabled. - - Setting this option option manually is not recommended but can be used - for some very technical nix-ing. If you wish to use a custom viewer, - please use the `custom` entry provided under `viewers`. - ''; + customOkular = { + enable = false; + package = pkgs.kdePackages.okular; + executable = "okular"; + args = [ + "--unique" + "file:%p#src:%l%f" + ]; + }; }; }; - config = mkIf (enabledPdfViewersInfo.count > 0) { + config = let + # List form of all pdf viewers. + pdfViewers = builtins.attrValues cfg.pdfViewer; + + countPdfViewers = viewers: (lib.lists.count (x: x.enable) viewers); + in { assertions = [ { - assertion = enabledPdfViewersInfo.count < 2; + # Assert that there is only one enabled pdf viewer. + assertion = (countPdfViewers pdfViewers) < 2; message = '' The nvf-tex-language implementation does not support having more than 1 pdf viewers enabled. diff --git a/modules/plugins/languages/tex/pdfViewer/getEnabledPdfViewer.nix b/modules/plugins/languages/tex/pdfViewer/getEnabledPdfViewer.nix new file mode 100644 index 00000000..e8790c84 --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/getEnabledPdfViewer.nix @@ -0,0 +1,22 @@ +{ + config, + lib, + ... +}: let + # The attribute set of pdf viewers in this configuration. + pdfViewers = config.vim.languages.tex.pdfViewer; + + # The list of pdf viewers in this configuration. + pdfViewersList = builtins.attrValues pdfViewers; + + # The list of enabled pdf viewers. + enabledPdfViewersList = builtins.filter (x: x.enable) pdfViewersList; + + # The number of enabled pdf viewers. + enabledPdfViewersCount = lib.lists.count (x: x.enable) pdfViewersList; +in + if (enabledPdfViewersCount == 0) + # Use the fallback if no pdf viewer was enabled. + then pdfViewers.fallback + # Otherwise get the first enabled viewer. + else builtins.head enabledPdfViewersList diff --git a/modules/plugins/languages/tex/pdfViewer/okular.nix b/modules/plugins/languages/tex/pdfViewer/okular.nix deleted file mode 100644 index 0c3d7f8d..00000000 --- a/modules/plugins/languages/tex/pdfViewer/okular.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ - pkgs, - lib, - ... -} @ moduleInheritancePackage: let - # The name of the pdf viewer - name = "okular"; - - # The viewer template - template = import ./viewerTemplate.nix; - - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) str listOf; -in ( - template { - inherit name moduleInheritancePackage; - - options = { - enable = mkEnableOption "enable okular as the pdf file previewer."; - - package = mkPackageOption pkgs "okular" {}; - - executable = mkOption { - type = str; - default = "okular"; - description = "The executable name to call the viewer."; - }; - - args = mkOption { - type = listOf str; - default = [ - "--unique" - "file:%p#src:%l%f" - ]; - description = "Arguments to pass to the viewer."; - }; - }; - - argsFunction = viewerCfg: (viewerCfg.args); - } -) diff --git a/modules/plugins/languages/tex/pdfViewer/premadePdfViewers.nix b/modules/plugins/languages/tex/pdfViewer/premadePdfViewers.nix new file mode 100644 index 00000000..622a058e --- /dev/null +++ b/modules/plugins/languages/tex/pdfViewer/premadePdfViewers.nix @@ -0,0 +1,80 @@ +{ + pkgs, + lib, + ... +}: let + inherit (lib) mkDefault mkForce; + + mkPdfViewerDefaults = { + package, + executable, + args ? [], + }: { + package = mkDefault package; + executable = mkDefault executable; + args = mkDefault args; + }; +in { + config.vim.languages.tex.pdfViewer = { + okular = mkPdfViewerDefaults { + package = pkgs.kdePackages.okular; + executable = "okular"; + args = [ + "--unique" + "file:%p#src:%l%f" + ]; + }; + + sioyek = mkPdfViewerDefaults { + package = pkgs.sioyek; + executable = "sioyek"; + args = [ + "--reuse-window" + "--execute-command" + "toggle_synctex" + "--inverse-search" + "texlab inverse-search -i \"%%1\" -l %%2" + "--forward-search-file" + "%f" + "--forward-search-line" + "%l" + "%p" + ]; + }; + + qpdfview = mkPdfViewerDefaults { + package = pkgs.qpdfview; + executable = "qpdfview"; + args = [ + "--unique" + "%p#src:%f:%l:1" + ]; + }; + + zathura = mkPdfViewerDefaults { + package = pkgs.zathura; + executable = "zathura"; + args = [ + "--synctex-forward" + "%l:1:%f" + "%p" + ]; + }; + + # This is a special pdf viewer. It is force set to a basic and known + # working configuration of okular and is used where needed in the + # rest of the tex language configuration encase no other pdf viewer + # was enabled. + # It cannot be enabled on its own and exists purely as a fallback + # option for internal use. + fallback = { + enable = mkForce false; + package = mkForce pkgs.kdePackages.okular; + executable = mkForce "okular"; + args = mkForce [ + "--unique" + "file:%p#src:%l%f" + ]; + }; + }; +} diff --git a/modules/plugins/languages/tex/pdfViewer/qpdfview.nix b/modules/plugins/languages/tex/pdfViewer/qpdfview.nix deleted file mode 100644 index 1938fb94..00000000 --- a/modules/plugins/languages/tex/pdfViewer/qpdfview.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ - pkgs, - lib, - ... -} @ moduleInheritancePackage: let - # The name of the pdf viewer - name = "qpdfview"; - - # The viewer template - template = import ./viewerTemplate.nix; - - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) str listOf; -in ( - template { - inherit name moduleInheritancePackage; - - options = { - enable = mkEnableOption "enable qpdfview as the pdf file previewer."; - - package = mkPackageOption pkgs "qpdfview" {}; - - executable = mkOption { - type = str; - default = "qpdfview"; - description = "The executable name to call the viewer."; - }; - - args = mkOption { - type = listOf str; - default = [ - "--unique" - "%p#src:%f:%l:1" - ]; - description = "Arguments to pass to the viewer."; - }; - }; - - argsFunction = viewerCfg: (viewerCfg.args); - } -) diff --git a/modules/plugins/languages/tex/pdfViewer/sioyek.nix b/modules/plugins/languages/tex/pdfViewer/sioyek.nix deleted file mode 100644 index ad0b4943..00000000 --- a/modules/plugins/languages/tex/pdfViewer/sioyek.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ - pkgs, - lib, - ... -} @ moduleInheritancePackage: let - # The name of the pdf viewer - name = "sioyek"; - - # The viewer template - template = import ./viewerTemplate.nix; - - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) str listOf; -in ( - template { - inherit name moduleInheritancePackage; - - options = { - enable = mkEnableOption "sioyek as the pdf file previewer."; - - package = mkPackageOption pkgs "sioyek" {}; - - executable = mkOption { - type = str; - default = "sioyek"; - description = "The executable name to call the viewer."; - }; - - args = mkOption { - type = listOf str; - default = [ - "--reuse-window" - "--execute-command" - "toggle_synctex" - "--inverse-search" - "texlab inverse-search -i \"%%1\" -l %%2" - "--forward-search-file" - "%f" - "--forward-search-line" - "%l" - "%p" - ]; - description = '' - Arguments to pass to the viewer. - - By default, this is the only viewer that supports the inverse search - feature by command line arguments and doesn't explicitly require extra - tinkering else where in your config. - ''; - }; - }; - - argsFunction = viewerCfg: (viewerCfg.args); - } -) diff --git a/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix b/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix deleted file mode 100644 index 72c52877..00000000 --- a/modules/plugins/languages/tex/pdfViewer/viewerTemplate.nix +++ /dev/null @@ -1,68 +0,0 @@ -# This function acts as a template for creating new pdf viewers. -# It enforces providing all the parameters required for creating -# a new pdf viewer for it to be able to work in the existing code. -# -# The first layer requirements are as follows: -{ - # This is the name of the pdf viewer, it will only be used internally and - # MUST match the .nix file that the pdf viewer is implemented in. - name, - # - # Module attribute set. This is the attribute set that the module that is - # defining a pdf viewer is passed as its input. - moduleInheritancePackage, - # - # These are the standard options for the pdf viewer just like creating any - # other module. Some options are required and are described below but - # it will also accept any other options that are provided to it. - options, - # - # These are the command line arguments that will accompany the executable - # when the view command is called. - # This is a function that will take in the cfg of its own pdf viewer. - # i.e. it will be called as "args cfg.pdfViewer.${name}" - argsFunction, - ... -}: let - # Inherit the necessary variables available to any module. - inherit (moduleInheritancePackage) lib config; - # - # Inherit other useful functions. - inherit (lib.modules) mkIf; - # - # Set the cfg variable - cfg = config.vim.languages.tex; - # - # Set the cfg of the viewer itself - viewerCfg = cfg.pdfViewer.${name}; -in { - # These are the options for the pdf viewer. It will accept any options - # provided to it but some options are mandatory: - options.vim.languages.tex.pdfViewer.${name} = ({ - # The enable option. This one is self explanatory. - enable, - # - # This is the package option for the pdf viewer. - package, - # - # This is the executable that will be used to call the pdf viewer. - # It, along with package will result in: - # "/bin/" - executable, - # - # Any other options provided are accepted. - ... - } @ opts: - opts) - options; - - # Check that the language and this pdf viewer have been enabled before making - # any config. - config = mkIf (cfg.enable && viewerCfg.enable) { - vim.languages.tex.pdfViewer = { - inherit name; - inherit (viewerCfg) package executable; - args = argsFunction viewerCfg; - }; - }; -} diff --git a/modules/plugins/languages/tex/pdfViewer/zathura.nix b/modules/plugins/languages/tex/pdfViewer/zathura.nix deleted file mode 100644 index f1fd16d5..00000000 --- a/modules/plugins/languages/tex/pdfViewer/zathura.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ - pkgs, - lib, - ... -} @ moduleInheritancePackage: let - # The name of the pdf viewer - name = "zathura"; - - # The viewer template - template = import ./viewerTemplate.nix; - - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) str listOf; -in ( - template { - inherit name moduleInheritancePackage; - - options = { - enable = mkEnableOption "enable zathura as the pdf file previewer."; - - package = mkPackageOption pkgs "zathura" {}; - - executable = mkOption { - type = str; - default = "zathura"; - description = "The executable name to call the viewer."; - }; - - args = mkOption { - type = listOf str; - default = [ - "--synctex-forward" - "%l:1:%f" - "%p" - ]; - description = "Arguments to pass to the viewer."; - }; - }; - - argsFunction = viewerCfg: (viewerCfg.args); - } -) From 353b63b6aca210d618d9e8bf7105efe65a90c848 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sun, 4 May 2025 12:20:36 -0600 Subject: [PATCH 63/65] Added description for pdf viewer --- modules/plugins/languages/tex/pdfViewer/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/plugins/languages/tex/pdfViewer/default.nix b/modules/plugins/languages/tex/pdfViewer/default.nix index ffa946af..20eed52a 100644 --- a/modules/plugins/languages/tex/pdfViewer/default.nix +++ b/modules/plugins/languages/tex/pdfViewer/default.nix @@ -87,6 +87,9 @@ in { ]; }; }; + description = '' + Define the pdf viewer to use for viewing compiled tex documents. + ''; }; config = let From 4d80eeb006e7e767e3883a2887c110930a183d63 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Sat, 15 Nov 2025 15:41:37 -0700 Subject: [PATCH 64/65] Changed lsp enable config variable referenced --- modules/plugins/languages/tex/lsp/texlab.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/languages/tex/lsp/texlab.nix b/modules/plugins/languages/tex/lsp/texlab.nix index 339fb40c..190f84f3 100644 --- a/modules/plugins/languages/tex/lsp/texlab.nix +++ b/modules/plugins/languages/tex/lsp/texlab.nix @@ -31,7 +31,7 @@ pdfViewer = import ../pdfViewer/getEnabledPdfViewer.nix {inherit lib config;}; in { options.vim.languages.tex.lsp.texlab = { - enable = mkBool config.vim.languages.enableLSP '' + enable = mkBool config.vim.lsp.enable '' Whether to enable Tex LSP support (texlab). ''; From 0da99e05aea9785240c87d5f216dbdb3b134504b Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Fri, 19 Dec 2025 14:30:30 -0700 Subject: [PATCH 65/65] Removed builderTemplate implementation in favour of an inline approach --- .../conform-nvim/builders/builderTemplate.nix | 66 --- .../conform-nvim/builders/latexmk.nix | 86 ++-- .../conform-nvim/builders/tectonic.nix | 340 +++++++--------- .../tex/build/builders/builderTemplate.nix | 66 --- .../languages/tex/build/builders/latexmk.nix | 92 +++-- .../languages/tex/build/builders/tectonic.nix | 375 ++++++++---------- 6 files changed, 400 insertions(+), 625 deletions(-) delete mode 100644 modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix delete mode 100644 modules/plugins/languages/tex/build/builders/builderTemplate.nix diff --git a/modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix b/modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix deleted file mode 100644 index 02d20412..00000000 --- a/modules/plugins/formatter/conform-nvim/builders/builderTemplate.nix +++ /dev/null @@ -1,66 +0,0 @@ -# This function acts as a template for creating new builders. -# It enforces providing all the parameters required for creating -# a new builder for it to be able to work in the existing code. -# -# The first layer requirements are as follows: -{ - # This is the name of the builder, it will only be used internally and - # should match the .nix file that the builder is implemented in. - name, - # - # Module attribute set. This is the attribute set that the module that is - # defining a builder is passed as its input. - moduleInheritancePackage, - # - # These are the standard options for the builder just like creating any - # other module. Some options are required and are described below but - # it will also accept any other options that are provided to it. - options, - # - # These are the command line arguments that will accompany the executable - # when the build command is called. - # This is a function that will take in the cfg of its own builder. - # i.e. will be called as "args cfg.build.builders.${name}" - args, - ... -}: let - # Inherit the necessary variables available to any module. - inherit (moduleInheritancePackage) lib config; - # - # Inherit other useful functions. - inherit (lib.modules) mkIf; - # - # Set the cfg variable - cfg = config.vim.languages.tex; -in { - # These are the options for the builder. It will accept any options - # provided to it but some options are mandatory: - options.vim.languages.tex.build.builders.${name} = ({ - # The enable option. This one is self explanatory. - enable, - # - # This is the package option for the builder. - package, - # - # This is the executable that will be used to call the builder. - # It, along with package will result in: - # "/bin/" - executable, - # - # Any other options provided are accepted. - ... - } @ opts: - opts) - options; - - # Check that the language and this builder have been enabled - # before making any config. - config = mkIf (cfg.enable && cfg.build.builders.${name}.enable) { - vim.languages.tex.build.builder = { - inherit name; - package = cfg.build.builders.${name}.package; - executable = cfg.build.builders.${name}.executable; - args = args cfg.build.builders.${name}; - }; - }; -} diff --git a/modules/plugins/formatter/conform-nvim/builders/latexmk.nix b/modules/plugins/formatter/conform-nvim/builders/latexmk.nix index 4d024eb3..510c9561 100644 --- a/modules/plugins/formatter/conform-nvim/builders/latexmk.nix +++ b/modules/plugins/formatter/conform-nvim/builders/latexmk.nix @@ -1,57 +1,53 @@ # TODO: I need testing. { - pkgs, + config, lib, + pkgs, ... -} @ moduleInheritancePackage: let +}: let # The name of the builder name = "latexmk"; - # The builder template - template = import ./builderTemplate.nix; - + inherit (lib.modules) mkIf; + inherit (lib.nvim.config) mkBool; inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) bool package str; -in ( - template { - inherit name moduleInheritancePackage; + inherit (lib.types) package str; - options = { - enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk"; + texCfg = config.vim.languages.tex; + cfg = texCfg.build.builders.${name}; +in { + options.vim.languages.tex.build.builders.${name} = { + enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk"; - package = mkOption { - type = package; - default = pkgs.texlive.withPackages (ps: [ps.latexmk]); - description = "latexmk package"; - }; - - executable = mkOption { - type = str; - default = "latexmk"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - - # Flag options - pdfOutput = mkOption { - type = bool; - default = true; - example = false; - description = "Insure the output file is a pdf."; - }; + package = mkOption { + type = package; + default = pkgs.texlive.withPackages (ps: [ps.latexmk]); + description = "latexmk package"; }; - args = builderCfg: ( - # Flags - ( - if builderCfg.pdfOutput - then ["-pdf"] - else [] - ) - # Base args - ++ [ - "-quiet" - "%f" - ] - ); - } -) + executable = mkOption { + type = str; + default = "latexmk"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # Flag options + pdfOutput = mkBool true "Insure the output file is a pdf."; + }; + + config = mkIf (texCfg.enable && cfg.enable) { + vim.languages.tex.build.builder = { + inherit name; + inherit (cfg) package executable; + args = ( + # Flags + (lib.lists.optional cfg.pdfOutput "-pdf") + # Base args + ++ [ + "-quiet" + "%f" + ] + ); + }; + }; +} diff --git a/modules/plugins/formatter/conform-nvim/builders/tectonic.nix b/modules/plugins/formatter/conform-nvim/builders/tectonic.nix index 1b131b33..0991cff4 100644 --- a/modules/plugins/formatter/conform-nvim/builders/tectonic.nix +++ b/modules/plugins/formatter/conform-nvim/builders/tectonic.nix @@ -1,203 +1,161 @@ { config, - pkgs, lib, + pkgs, ... -} @ moduleInheritancePackage: let +}: let # The name of the builder name = "tectonic"; - # The builder template - template = import ./builderTemplate.nix; - - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) enum ints listOf package str; + inherit (builtins) concatLists elem map toString match; + inherit (lib.modules) mkIf; inherit (lib.nvim.config) mkBool; - inherit (builtins) concatLists elem map toString; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.strings) toLower optionalString stringAsChars; + inherit (lib.types) enum ints listOf package str; - cfg = config.vim.languages.tex; -in ( - template { - inherit name moduleInheritancePackage; + texCfg = config.vim.languages.tex; + cfg = texCfg.build.builders.${name}; +in { + options.vim.languages.tex.build.builders.${name} = { + enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; - options = { - enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic"; - - package = mkOption { - type = package; - default = pkgs.tectonic; - description = "tectonic package"; - }; - - executable = mkOption { - type = str; - default = "tectonic"; - description = "The executable name from the build package that will be used to build/compile the tex."; - }; - - # -- Flags -- - keepIntermediates = mkBool false '' - Keep the intermediate files generated during processing. - - If texlab is reporting build errors when there shouldn't be, disable this option. - ''; - keepLogs = mkBool true '' - Keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation warnings. - ''; - onlyCached = mkBool false "Use only resource files cached locally"; - synctex = mkBool true "Generate SyncTeX data"; - untrustedInput = mkBool false "Input is untrusted -- disable all known-insecure features"; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = '' - Rerun the TeX engine exactly this many times after the first. - - Setting this value to 0 will disable setting this option. - ''; - }; - - bundle = mkOption { - type = str; - default = ""; - description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; - }; - - webBundle = mkOption { - type = str; - default = ""; - description = "Use this URL to find resource files instead of the default"; - }; - - outfmt = mkOption { - type = enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - "" - ]; - default = ""; - description = "The kind of output to generate"; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = "Tell the engine that no file at exists, if it tries to read it."; - }; - - format = mkOption { - type = str; - default = ""; - description = "The name of the \"format\" file used to initialize the TeX engine"; - }; - - color = mkOption { - type = enum [ - "always" - "auto" - "never" - "" - ]; - default = ""; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build command. - Extra options added here will not overwrite the options set in as nvf options. - ''; - }; + package = mkOption { + type = package; + default = pkgs.tectonic; + description = "tectonic package"; }; - args = builderCfg: ( - # Base args - [ - "-X" - "compile" - "%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 [] - ) - # 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 [] - ) - ++ (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 [] - ) - # 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 [] - ) - ); - } -) + executable = mkOption { + type = str; + default = "tectonic"; + description = "The executable name from the build package that will be used to build/compile the tex."; + }; + + # -- Flags -- + keepIntermediates = mkBool false '' + Keep the intermediate files generated during processing. + + If texlab is reporting build errors when there shouldn't be, disable this option. + ''; + keepLogs = mkBool true '' + Keep the log files generated during processing. + + Without the keepLogs flag, texlab won't be able to report compilation warnings. + ''; + onlyCached = mkBool false "Use only resource files cached locally"; + synctex = mkBool true "Generate SyncTeX data"; + untrustedInput = mkBool false "Input is untrusted -- disable all known-insecure features"; + + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = '' + Rerun the TeX engine exactly this many times after the first. + + Setting this value to 0 will disable setting this option. + ''; + }; + + bundle = mkOption { + type = str; + default = ""; + description = "Use this directory or Zip-format bundle file to find resource files instead of the default"; + }; + + webBundle = mkOption { + type = str; + default = ""; + description = "Use this URL to find resource files instead of the default"; + }; + + outfmt = mkOption { + type = enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + "" + ]; + default = ""; + description = "The kind of output to generate"; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = "Tell the engine that no file at exists, if it tries to read it."; + }; + + format = mkOption { + type = str; + default = ""; + description = "The name of the \"format\" file used to initialize the TeX engine"; + }; + + color = mkOption { + type = enum [ + "always" + "auto" + "never" + "" + ]; + default = ""; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build command. + Extra options added here will not overwrite the options set in as nvf options. + ''; + }; + }; + + config = mkIf (texCfg.enable && cfg.enable) { + vim.languages.tex.build.builder = { + inherit name; + inherit (cfg) package executable; + args = let + inherit (lib.lists) optional optionals; + snakeCaseToKebabCase = str: stringAsChars (x: "${optionalString ((match "[A-Z]" x) != null) "-"}${toLower x}") str; + generateOptionFlag = option: (optionals (cfg.${option} != "") ["--${snakeCaseToKebabCase option}" "${toString cfg.${option}}"]); + in ( + # Base args + [ + "-X" + "compile" + "%f" + ] + # Flags + ++ (optional cfg.keepIntermediates "--keep-intermediates") + ++ (optional cfg.keepLogs "--keep-logs") + ++ (optional cfg.onlyCached "--only-cached") + ++ (optional cfg.synctex "--synctex") + ++ (optional cfg.untrustedInput "--untrusted") + # Options + ++ (optionals (cfg.reruns > 0) ["--reruns" "${toString cfg.reruns}"]) + ++ (generateOptionFlag "bundle") + ++ (generateOptionFlag "webBundle") + ++ (generateOptionFlag "outfmt") + ++ (concatLists (map (x: ["--hide" x]) cfg.hidePaths)) + ++ (generateOptionFlag "format") + ++ (generateOptionFlag "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. + ++ (optionals (!(elem texCfg.build.pdfDirectory ["." ""])) ["--outdir" "${texCfg.build.pdfDirectory}"]) + ); + }; + }; +} diff --git a/modules/plugins/languages/tex/build/builders/builderTemplate.nix b/modules/plugins/languages/tex/build/builders/builderTemplate.nix deleted file mode 100644 index 02d20412..00000000 --- a/modules/plugins/languages/tex/build/builders/builderTemplate.nix +++ /dev/null @@ -1,66 +0,0 @@ -# This function acts as a template for creating new builders. -# It enforces providing all the parameters required for creating -# a new builder for it to be able to work in the existing code. -# -# The first layer requirements are as follows: -{ - # This is the name of the builder, it will only be used internally and - # should match the .nix file that the builder is implemented in. - name, - # - # Module attribute set. This is the attribute set that the module that is - # defining a builder is passed as its input. - moduleInheritancePackage, - # - # These are the standard options for the builder just like creating any - # other module. Some options are required and are described below but - # it will also accept any other options that are provided to it. - options, - # - # These are the command line arguments that will accompany the executable - # when the build command is called. - # This is a function that will take in the cfg of its own builder. - # i.e. will be called as "args cfg.build.builders.${name}" - args, - ... -}: let - # Inherit the necessary variables available to any module. - inherit (moduleInheritancePackage) lib config; - # - # Inherit other useful functions. - inherit (lib.modules) mkIf; - # - # Set the cfg variable - cfg = config.vim.languages.tex; -in { - # These are the options for the builder. It will accept any options - # provided to it but some options are mandatory: - options.vim.languages.tex.build.builders.${name} = ({ - # The enable option. This one is self explanatory. - enable, - # - # This is the package option for the builder. - package, - # - # This is the executable that will be used to call the builder. - # It, along with package will result in: - # "/bin/" - executable, - # - # Any other options provided are accepted. - ... - } @ opts: - opts) - options; - - # Check that the language and this builder have been enabled - # before making any config. - config = mkIf (cfg.enable && cfg.build.builders.${name}.enable) { - vim.languages.tex.build.builder = { - inherit name; - package = cfg.build.builders.${name}.package; - executable = cfg.build.builders.${name}.executable; - args = args cfg.build.builders.${name}; - }; - }; -} diff --git a/modules/plugins/languages/tex/build/builders/latexmk.nix b/modules/plugins/languages/tex/build/builders/latexmk.nix index bbb4ecd5..a840f1b2 100644 --- a/modules/plugins/languages/tex/build/builders/latexmk.nix +++ b/modules/plugins/languages/tex/build/builders/latexmk.nix @@ -1,59 +1,57 @@ # TODO: I need testing. { - pkgs, + config, lib, + pkgs, ... -} @ moduleInheritancePackage: let +}: let # The name of the builder name = "latexmk"; - # The builder template - template = import ./builderTemplate.nix; - - inherit (lib) optionals; + inherit (lib.modules) mkIf; + inherit (lib.nvim.config) mkBool; inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) bool package str; -in ( - template { - inherit name moduleInheritancePackage; + inherit (lib.types) package str; - options = { - enable = mkEnableOption "Tex Compilation Via latexmk"; + texCfg = config.vim.languages.tex; + cfg = texCfg.build.builders.${name}; +in { + options.vim.languages.tex.build.builders.${name} = { + enable = mkEnableOption "Tex Compilation Via latexmk"; - package = mkOption { - type = package; - default = pkgs.texlive.withPackages (ps: [ps.latexmk]); - description = "latexmk package"; - }; - - executable = mkOption { - type = str; - default = "latexmk"; - description = '' - The executable name from the build package that will be used to - build/compile the tex. - ''; - }; - - # Flag options - pdfOutput = mkOption { - type = bool; - default = true; - example = false; - description = "Insure the output file is a pdf."; - }; + package = mkOption { + type = package; + default = pkgs.texlive.withPackages (ps: [ps.latexmk]); + description = "latexmk package"; }; - # Optional flags must come before the base args because of how the latexmk - # command works - args = builderCfg: ( - # Flags - (optionals builderCfg.pdfOutput ["-pdf"]) - # Base args - ++ [ - "-quiet" - "%f" - ] - ); - } -) + executable = mkOption { + type = str; + default = "latexmk"; + description = '' + The executable name from the build package that will be used to + build/compile the tex. + ''; + }; + + # Flag options + pdfOutput = mkBool true "Insure the output file is a pdf."; + }; + + config = mkIf (texCfg.enable && cfg.enable) { + vim.languages.tex.build.builder = { + inherit name; + inherit (cfg) package executable; + + args = ( + # Flags + (lib.lists.optional cfg.pdfOutput "-pdf") + # Base args + ++ [ + "-quiet" + "%f" + ] + ); + }; + }; +} diff --git a/modules/plugins/languages/tex/build/builders/tectonic.nix b/modules/plugins/languages/tex/build/builders/tectonic.nix index 6c680cff..f65db0ea 100644 --- a/modules/plugins/languages/tex/build/builders/tectonic.nix +++ b/modules/plugins/languages/tex/build/builders/tectonic.nix @@ -1,229 +1,184 @@ { config, - pkgs, lib, + pkgs, ... -} @ moduleInheritancePackage: let +}: let # The name of the builder name = "tectonic"; - # The builder template - template = import ./builderTemplate.nix; - - inherit (lib) optionals; - inherit (lib.options) mkOption mkEnableOption mkPackageOption; - inherit (lib.types) enum ints listOf str nullOr; + inherit (builtins) concatLists elem map toString match; + inherit (lib.modules) mkIf; inherit (lib.nvim.config) mkBool; - inherit (builtins) concatLists elem map toString attrNames filter isList; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.strings) toLower optionalString stringAsChars; + inherit (lib.types) enum ints listOf str nullOr; - notNull = x: x != null; - forceCheck = x: true; - toList = x: - if isList x - then x - else [x]; + texCfg = config.vim.languages.tex; + cfg = texCfg.build.builders.${name}; +in { + options.vim.languages.tex.build.builders.${name} = { + enable = mkEnableOption "Tex Compilation Via Tectonic"; - cfg = config.vim.languages.tex; -in ( - template { - inherit name moduleInheritancePackage; + package = mkPackageOption pkgs "tectonic" {}; - options = { - enable = mkEnableOption "Tex Compilation Via Tectonic"; - - package = mkPackageOption pkgs "tectonic" {}; - - executable = mkOption { - type = str; - default = "tectonic"; - description = '' - The executable name from the build package that will be used to - build/compile the tex. - ''; - }; - - # -- Flags -- - keepIntermediates = mkBool false '' - Whether to keep the intermediate files generated during processing. - - If texlab is reporting build errors when there shouldn't be, disable - this option. + executable = mkOption { + type = str; + default = "tectonic"; + description = '' + The executable name from the build package that will be used to + build/compile the tex. ''; - keepLogs = mkBool true '' - Whether to keep the log files generated during processing. - - Without the keepLogs flag, texlab won't be able to report compilation - warnings. - ''; - onlyCached = mkBool false '' - Whether to use only resource files cached locally - ''; - synctex = mkBool true "Whether to generate SyncTeX data"; - untrustedInput = mkBool false '' - Whether to disable all known-insecure features if the input is untrusted - ''; - - # -- Options -- - reruns = mkOption { - type = ints.unsigned; - default = 0; - example = 2; - description = '' - How many times to *rerun* the TeX build engine. - The build engine (if a builder is enabled) will always run at least - once. - - Setting this value to 0 will disable setting this option. - ''; - }; - - bundle = mkOption { - type = nullOr str; - default = null; - description = '' - The directory or Zip-format bundle file to find resource files instead - of the default. - ''; - }; - - webBundle = mkOption { - type = nullOr str; - default = null; - description = '' - Use this URL to find resource files instead of the default. - ''; - }; - - outfmt = mkOption { - type = nullOr (enum [ - "pdf" - "html" - "xdv" - "aux" - "fmt" - ]); - default = null; - description = '' - The kind of output to generate. - - Setting this to `null` (default) will let tectonic decide the most - appropriate output format, which usually be a pdf. - ''; - }; - - hidePaths = mkOption { - type = listOf str; - default = []; - example = [ - "./secrets.tex" - "./passwords.tex" - ]; - description = '' - Tell the engine that no file at `` exists, if it tries - to read it. - ''; - }; - - format = mkOption { - type = nullOr str; - default = null; - description = '' - The name of the \"format\" file used to initialize the TeX engine. - ''; - }; - - color = mkOption { - type = nullOr (enum [ - "always" - "auto" - "never" - ]); - default = null; - example = "always"; - description = "Enable/disable colorful log output"; - }; - - extraOptions = mkOption { - type = listOf str; - default = []; - description = '' - Add extra command line options to include in the tectonic build - command. - Extra options added here will not overwrite the options set in as nvf - options. - ''; - }; }; - # args = builderCfg: ( - # # Base args - # [ - # "-X" - # "compile" - # "%f" - # ] - # # Flags - # ++ (optionals builderCfg.keepIntermediates ["--keep-intermediates"]) - # ++ (optionals builderCfg.keepLogs ["--keep-logs"]) - # ++ (optionals builderCfg.onlyCached ["--only-cached"]) - # ++ (optionals builderCfg.synctex ["--synctex"]) - # ++ (optionals builderCfg.untrustedInput ["--untrusted"]) - # # Options - # ++ (optionals (builderCfg.reruns > 0) ["--reruns" "${toString builderCfg.reruns}"]) - # ++ (optionals (builderCfg.bundle != null) ["--bundle" "${toString builderCfg.bundle}"]) - # ++ (optionals (builderCfg.webBundle != null) ["--web-bundle" "${toString builderCfg.webBundle}"]) - # ++ (optionals (builderCfg.outfmt != null) ["--outfmt" "${toString builderCfg.outfmt}"]) - # ++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths)) - # ++ (optionals (builderCfg.format != null) ["--format" "${toString builderCfg.format}"]) - # ++ (optionals (builderCfg.color != null) ["--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 - # ++ (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"]) - # ); + # -- Flags -- + keepIntermediates = mkBool false '' + Whether to keep the intermediate files generated during processing. - args = builderCfg: let - option = setCheck: flag: {inherit setCheck flag;}; - args = { - baseArgs = ["-X" "compile" "%f"]; + If texlab is reporting build errors when there shouldn't be, disable + this option. + ''; + keepLogs = mkBool true '' + Whether to keep the log files generated during processing. - flags = { - keepIntermediates = "--keep-intermediates"; - keepLogs = "--keep-logs"; - onlyCached = "--only-cached"; - synctex = "--synctex"; - untrustedInput = "--untrusted"; - }; + Without the keepLogs flag, texlab won't be able to report compilation + warnings. + ''; + onlyCached = mkBool false '' + Whether to use only resource files cached locally + ''; + synctex = mkBool true "Whether to generate SyncTeX data"; + untrustedInput = mkBool false '' + Whether to disable all known-insecure features if the input is untrusted + ''; - options = { - reruns = option (x: x > 0) "--reruns"; - bundle = option notNull "--bundle"; - webBundle = option notNull "--web-bundle"; - outfmt = option notNull "--outfmt"; - format = option notNull "--format"; - color = option notNull "--color"; - hidePaths = option forceCheck "--hide"; - }; + # -- Options -- + reruns = mkOption { + type = ints.unsigned; + default = 0; + example = 2; + description = '' + How many times to *rerun* the TeX build engine. + The build engine (if a builder is enabled) will always run at least + once. - externalOptions = concatLists [ - (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"]) - ]; - }; + Setting this value to 0 will disable setting this option. + ''; + }; - flags = map (flag: args.flags.${flag}) (filter (flag: builderCfg.${flag}) (attrNames args.flags)); - options = let - getOptionFlagsList = opt: - concatLists ( - map - (y: [args.options."${opt}".flag "${toString y}"]) - (toList builderCfg."${opt}") - ); - processOption = opt: - optionals - (args.options."${opt}".setCheck builderCfg."${opt}") - (getOptionFlagsList opt); - in (concatLists (map processOption (attrNames args.options))); - in - concatLists (with args; [baseArgs flags options externalOptions]); - } -) + bundle = mkOption { + type = nullOr str; + default = null; + description = '' + The directory or Zip-format bundle file to find resource files instead + of the default. + ''; + }; + + webBundle = mkOption { + type = nullOr str; + default = null; + description = '' + Use this URL to find resource files instead of the default. + ''; + }; + + outfmt = mkOption { + type = nullOr (enum [ + "pdf" + "html" + "xdv" + "aux" + "fmt" + ]); + default = null; + description = '' + The kind of output to generate. + + Setting this to `null` (default) will let tectonic decide the most + appropriate output format, which usually be a pdf. + ''; + }; + + hidePaths = mkOption { + type = listOf str; + default = []; + example = [ + "./secrets.tex" + "./passwords.tex" + ]; + description = '' + Tell the engine that no file at `` exists, if it tries + to read it. + ''; + }; + + format = mkOption { + type = nullOr str; + default = null; + description = '' + The name of the \"format\" file used to initialize the TeX engine. + ''; + }; + + color = mkOption { + type = nullOr (enum [ + "always" + "auto" + "never" + ]); + default = null; + example = "always"; + description = "Enable/disable colorful log output"; + }; + + extraOptions = mkOption { + type = listOf str; + default = []; + description = '' + Add extra command line options to include in the tectonic build + command. + Extra options added here will not overwrite the options set in as nvf + options. + ''; + }; + }; + + config = mkIf (texCfg.enable && cfg.enable) { + vim.languages.tex.build.builder = { + inherit name; + inherit (cfg) package executable; + + args = let + inherit (lib.lists) optional optionals; + snakeCaseToKebabCase = str: stringAsChars (x: "${optionalString ((match "[A-Z]" x) != null) "-"}${toLower x}") str; + generateOptionFlag = option: (optionals (cfg.${option} != "" && cfg.${option} != null) ["--${snakeCaseToKebabCase option}" "${toString cfg.${option}}"]); + in ( + # Base args + [ + "-X" + "compile" + "%f" + ] + # Flags + ++ (optional cfg.keepIntermediates "--keep-intermediates") + ++ (optional cfg.keepLogs "--keep-logs") + ++ (optional cfg.onlyCached "--only-cached") + ++ (optional cfg.synctex "--synctex") + ++ (optional cfg.untrustedInput "--untrusted") + # Options + ++ (optionals (cfg.reruns > 0) ["--reruns" "${toString cfg.reruns}"]) + ++ (generateOptionFlag "bundle") + ++ (generateOptionFlag "webBundle") + ++ (generateOptionFlag "outfmt") + ++ (concatLists (map (x: ["--hide" x]) cfg.hidePaths)) + ++ (generateOptionFlag "format") + ++ (generateOptionFlag "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. + ++ (optionals (!(elem texCfg.build.pdfDirectory ["." ""])) ["--outdir" "${texCfg.build.pdfDirectory}"]) + ); + }; + }; +}