feat: add option for customizing lsp capabilities (#1021)

This commit is contained in:
Jake Hamilton 2024-03-06 12:50:14 -08:00 committed by GitHub
parent 4448c4ce63
commit c4ae452396
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -146,6 +146,15 @@ in {
description = "The server's name"; 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 { extraOptions = mkOption {
type = attrs; type = attrs;
description = "Extra options for the server"; description = "Extra options for the server";
@ -196,6 +205,27 @@ in {
if wrappers == [] if wrappers == []
then s then s
else (head wrappers) (runWrappers (tail wrappers) 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 in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = [pkgs.vimPlugins.nvim-lspconfig]; extraPlugins = [pkgs.vimPlugins.nvim-lspconfig];
@ -237,6 +267,8 @@ in {
local __lspServers = ${helpers.toLuaObject cfg.enabledServers} local __lspServers = ${helpers.toLuaObject cfg.enabledServers}
local __lspOnAttach = function(client, bufnr) local __lspOnAttach = function(client, bufnr)
${updateCapabilities}
${cfg.onAttach} ${cfg.onAttach}
end end
local __lspCapabilities = function() local __lspCapabilities = function()