Skip to content

Commit

Permalink
add lsp server support to kate
Browse files Browse the repository at this point in the history
  • Loading branch information
blitter committed Apr 10, 2024
1 parent 4b127a5 commit ac2c48e
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion modules/apps/kate/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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" ]
Expand All @@ -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; };
};
}

0 comments on commit ac2c48e

Please sign in to comment.