From ac2c48e58602e8c7bcee144caf6e1eb6669e12ce Mon Sep 17 00:00:00 2001 From: blitter Date: Wed, 10 Apr 2024 02:39:13 +0200 Subject: [PATCH] add lsp server support to kate --- modules/apps/kate/default.nix | 77 ++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/modules/apps/kate/default.nix b/modules/apps/kate/default.nix index 510453d3..8ddc5995 100644 --- a/modules/apps/kate/default.nix +++ b/modules/apps/kate/default.nix @@ -26,6 +26,53 @@ let ''; script = pkgs.writeScript "kate-check" (checkThemeName cfg.editor.theme.name); + + supportedLspServers = { + # https://github.com/oxalica/nil?tab=readme-ov-file#kate-with-lsp-client-plugin + nil = { + name = "nix"; # the name in the settings file. no collisions in the end! + settings = { + command = [ "nil" ]; + url = "https://github.com/oxalica/nil"; + highlightingModeRegex = "^Nix$"; + }; + package = pkgs.nil; + }; + + marksman = { + #https://www.reddit.com/r/kde/comments/webug0/trying_to_get_marksman_markdown_lsp_to_work_in/ + name = "markdown"; + settings = { + command = [ "marksman" "server" ]; + url = "https://github.com/artempyanykh/marksman"; + highlightingModeRegex = "^Markdown$"; + }; + package = pkgs.marksman; + }; + }; + + installedLspSettings = + cfg.lsp.extraSettings // + ( + # rename the settings to the language name + lib.mapAttrs' + (name: value: lib.nameValuePair value.name value.settings) + ( + # pick only the lspServers which the user chose + lib.filterAttrs + (n: v: builtins.elem n cfg.lsp.servers) + supportedLspServers + ) + ); + + lspPackages = + lib.attrVals + cfg.lsp.servers + ( + lib.mapAttrs + (name: value: value.package) + supportedLspServers + ); in { options.programs.kate = { @@ -175,7 +222,11 @@ in }; config = { - home.packages = lib.mkIf (cfg.enable && cfg.package != null) [ cfg.package ]; + home.packages = lib.mkIf cfg.enable + ( + (lib.lists.optional (cfg.package != null) cfg.package) + ++ lspPackages + ); # In case of using a custom theme, check that there is no name collision home.activation.checkKateTheme = lib.mkIf (cfg.enable && cfg.editor.theme.src != null) (lib.hm.dag.entryBefore [ "writeBoundary" ] @@ -189,4 +240,28 @@ in # That's why there is no check for now # See also [the original PR](https://github.com/pjones/plasma-manager/pull/95#issue-2206192839) }; + + + # ================================== + # LSP Servers + + options.programs.kate.lsp.servers = lib.mkOption { + default = []; + type = lib.types.listOf ( lib.types.enum (builtins.attrNames supportedLspServers) ); + description = '' + List of all preconfigured LSP servers to use. + ''; + }; + + options.programs.kate.lsp.extraSettings = lib.mkOption { + default = {}; + type = lib.types.attrs; + description = '' + Add more lsp server settings here. Check out the format on the [KDE page](https://kate-editor.org/post/2019/2019-08-10-kate-lsp-more-languages-supported/). + ''; + }; + + config.xdg.configFile."kate/lspclient/settings.json" = { + text = builtins.toJSON { servers = installedLspSettings; }; + }; }