From c4ae4523969b44c0e20d9ef7373b609823bb90f3 Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Wed, 6 Mar 2024 12:50:14 -0800 Subject: [PATCH] feat: add option for customizing lsp capabilities (#1021) --- plugins/lsp/default.nix | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/plugins/lsp/default.nix b/plugins/lsp/default.nix index 45d9791b..3e668ecb 100644 --- a/plugins/lsp/default.nix +++ b/plugins/lsp/default.nix @@ -146,6 +146,15 @@ in { description = "The server's name"; }; + capabilities = mkOption { + type = types.nullOr (types.attrsOf types.bool); + description = "Control resolved capabilities for the language server."; + default = null; + example = { + documentFormattingProvider = false; + }; + }; + extraOptions = mkOption { type = attrs; description = "Extra options for the server"; @@ -196,6 +205,27 @@ in { if wrappers == [] then s else (head wrappers) (runWrappers (tail wrappers) s); + updateCapabilities = let + servers = + builtins.filter + (server: server.capabilities != null && server.capabilities != {}) + cfg.enabledServers; + in + lib.concatMapStringsSep "\n" ( + server: let + updates = + lib.concatMapStringsSep "\n" + (name: '' + client.server_capabilities.${name} = ${helpers.toLuaObject server.capabilities.${name}} + '') + (builtins.attrNames server.capabilities); + in '' + if client.name == "${server.name}" then + ${updates} + end + '' + ) + servers; in mkIf cfg.enable { extraPlugins = [pkgs.vimPlugins.nvim-lspconfig]; @@ -237,6 +267,8 @@ in { local __lspServers = ${helpers.toLuaObject cfg.enabledServers} local __lspOnAttach = function(client, bufnr) + ${updateCapabilities} + ${cfg.onAttach} end local __lspCapabilities = function()