From b31be39a7a42c13b537ed3e1ff92f7b8107104be Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Fri, 21 Mar 2025 18:12:19 +0100 Subject: [PATCH] Move kak-lsp config to new format --- flake.lock | 8 +-- flake.nix | 2 +- home/modules/programs/my-kakoune/default.nix | 1 + overlay.nix | 2 +- packages/common/nki-kakoune/lsp.nix | 70 +++++++++++++++++--- 5 files changed, 69 insertions(+), 14 deletions(-) diff --git a/flake.lock b/flake.lock index 22da353..cadb6d5 100644 --- a/flake.lock +++ b/flake.lock @@ -639,16 +639,16 @@ "kak-lsp": { "flake": false, "locked": { - "lastModified": 1737458684, - "narHash": "sha256-wIKAChmD6gVfrRguywiAnpT3kbCbRk2k2u4ckd1CNOw=", + "lastModified": 1742457498, + "narHash": "sha256-2jD0meehUNGvmywOY4D9CwP1qswD7QCPlctLBjngzvE=", "owner": "kakoune-lsp", "repo": "kakoune-lsp", - "rev": "d5db3de3b88a8a158e1bfa43f13d8766a6c6d522", + "rev": "30dfe2873dae089981d63d3405323a8e9def0468", "type": "github" }, "original": { "owner": "kakoune-lsp", - "ref": "v18.1.2", + "ref": "v18.1.3", "repo": "kakoune-lsp", "type": "github" } diff --git a/flake.nix b/flake.nix index 9e9b23d..bf55c26 100644 --- a/flake.nix +++ b/flake.nix @@ -51,7 +51,7 @@ # --- Sources kakoune.url = "github:mawww/kakoune"; kakoune.flake = false; - kak-lsp.url = "github:kakoune-lsp/kakoune-lsp/v18.1.2"; + kak-lsp.url = "github:kakoune-lsp/kakoune-lsp/v18.1.3"; kak-lsp.flake = false; nixos-m1.url = "github:tpwrules/nixos-apple-silicon"; nixos-m1.inputs.nixpkgs.follows = "nixpkgs"; diff --git a/home/modules/programs/my-kakoune/default.nix b/home/modules/programs/my-kakoune/default.nix index 62a9cb1..18d6dec 100644 --- a/home/modules/programs/my-kakoune/default.nix +++ b/home/modules/programs/my-kakoune/default.nix @@ -59,6 +59,7 @@ in }; }) cfg.autoloadFile; + xdg.dataFile."kak".source = "${cfg.package}/share/kak"; }; } diff --git a/overlay.nix b/overlay.nix index 325d349..cfadce4 100644 --- a/overlay.nix +++ b/overlay.nix @@ -94,7 +94,7 @@ let kak-lsp = final.unstable.rustPlatform.buildRustPackage { name = "kak-lsp"; src = inputs.kak-lsp; - cargoHash = "sha256-U9KxTHzIDtdJ3A62rcdvWlxJfnhbFnS6KDRaV0HJOHE="; + cargoHash = "sha256-8Y+haxC7ssN07ODZcKoDdTv0vEnKqxYseLPoQSNmWI4="; buildInputs = [ final.libiconv ]; meta.mainProgram = "kak-lsp"; diff --git a/packages/common/nki-kakoune/lsp.nix b/packages/common/nki-kakoune/lsp.nix index e6c9f85..9c5790e 100644 --- a/packages/common/nki-kakoune/lsp.nix +++ b/packages/common/nki-kakoune/lsp.nix @@ -259,16 +259,64 @@ let }; }; - kak-lsp-config = + per-lang-config = lang: let toml = formats.toml { }; - toLspConfig = builtins.mapAttrs (_: attrs: builtins.removeAttrs attrs [ "package" ]); + servers = lib.filterAttrs (_: server: builtins.elem lang server.filetypes) config.languageServers; + serverSettings = lib.mapAttrs + (name: server: builtins.removeAttrs + (server // { + root_globs = server.roots; + }) [ "package" "filetypes" "roots" ]) + servers; + serversToml = toml.generate "kak-lsp-${lang}.toml" serverSettings; + lang-id = + if builtins.hasAttr lang config.languageIDs then '' + set-option buffer lsp_language_id ${config.languageIDs.${lang}} + '' else "# No lang-id remap needed"; in - toml.generate "kak-lsp.toml" ({ - semantic_tokens.faces = config.faces; - language_server = toLspConfig config.languageServers; - language_ids = config.languageIDs; - } // config.raw); + '' + # LSP Configuration for ${lang} + hook -group lsp-filetype-${lang} global BufSetOption filetype=(?:${lang}) %{ + set-option buffer lsp_servers %{ + ${builtins.readFile serversToml} + } + ${lang-id} + } + ''; + + lang-config = + let + langs = lib.unique (lib.flatten (lib.mapAttrsToList (_: server: server.filetypes) config.languageServers)); + in + lib.concatMapStringsSep "\n" per-lang-config langs; + faces-config = + let + mapFace = face: + let + modifiers = if builtins.hasAttr "modifiers" face then ", modifiers=${builtins.toJSON face.modifiers}" else ""; + in + "{face=${builtins.toJSON face.face}, token=${builtins.toJSON face.token}${modifiers}}"; + faces = lib.concatMapStringsSep ",\n " mapFace config.faces; + in + '' + set-option global lsp_semantic_tokens %{ + [ + ${faces} + ] + } + ''; + + # kak-lsp-config = + # let + # toml = formats.toml { }; + # toLspConfig = builtins.mapAttrs (_: attrs: builtins.removeAttrs attrs [ "package" ]); + # in + # toml.generate "kak-lsp.toml" ({ + # semantic_tokens.faces = config.faces; + # language_server = toLspConfig config.languageServers; + # language_ids = config.languageIDs; + # } // config.raw); serverPackages = builtins.filter (v: v != null) @@ -279,7 +327,7 @@ in plugin = writeTextDir "share/kak/autoload/kak-lsp.kak" '' hook global KakBegin .* %{ try %{ - eval %sh{kak-lsp --kakoune --config ${kak-lsp-config} -s $kak_session} + eval %sh{kak-lsp --kakoune -s $kak_session} } lsp-enable @@ -327,6 +375,12 @@ in define-command -params 0 -docstring "Import build" scala-build-import %{ lsp-execute-command 'build-import' '[]' } + + ## Language settings + ${lang-config} + + ## Faces + ${faces-config} } ''; }