From 08283679ff42e2d1a23eefab51fe8bc54ffa7420 Mon Sep 17 00:00:00 2001 From: isaacST08 Date: Thu, 30 Jan 2025 13:56:38 -0700 Subject: [PATCH] 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