2021-02-01 15:54:53 +00:00
|
|
|
{
|
2023-02-20 11:42:13 +01:00
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.plugins.lsp;
|
|
|
|
helpers = import ../helpers.nix {inherit lib;};
|
|
|
|
in {
|
2021-02-01 15:54:53 +00:00
|
|
|
imports = [
|
2023-02-23 00:42:44 +01:00
|
|
|
./language-servers
|
2021-02-01 15:54:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
2022-09-18 11:19:23 +01:00
|
|
|
plugins.lsp = {
|
2023-01-22 03:32:08 +00:00
|
|
|
enable = mkEnableOption "neovim's built-in LSP";
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2023-03-14 15:22:56 +01:00
|
|
|
keymaps = {
|
|
|
|
silent = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether nvim-lsp keymaps should be silent";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
diagnostic = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = "Mappings for `vim.diagnostic.<action>` functions.";
|
|
|
|
example = {
|
|
|
|
"<leader>k" = "goto_prev";
|
|
|
|
"<leader>j" = "goto_next";
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
lspBuf = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = "Mappings for `vim.lsp.buf.<action>` functions.";
|
|
|
|
example = {
|
|
|
|
"gd" = "definition";
|
|
|
|
"gD" = "references";
|
|
|
|
"gt" = "type_definition";
|
|
|
|
"gi" = "implementation";
|
|
|
|
"K" = "hover";
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-01 15:54:53 +00:00
|
|
|
enabledServers = mkOption {
|
2023-02-20 11:42:13 +01:00
|
|
|
type = with types;
|
|
|
|
listOf (oneOf [
|
|
|
|
str
|
|
|
|
(submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The server's name";
|
|
|
|
};
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
extraOptions = mkOption {
|
|
|
|
type = attrs;
|
|
|
|
description = "Extra options for the server";
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
})
|
|
|
|
]);
|
2021-02-01 15:54:53 +00:00
|
|
|
description = "A list of enabled LSP servers. Don't use this directly.";
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2021-02-01 15:54:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
onAttach = mkOption {
|
|
|
|
type = types.lines;
|
2022-12-05 09:49:37 +07:00
|
|
|
description = "A lua function to be run when a new LSP buffer is attached. The argument `client` and `bufnr` is provided.";
|
2021-02-01 15:54:53 +00:00
|
|
|
default = "";
|
|
|
|
};
|
2021-11-23 15:39:57 +01:00
|
|
|
|
2023-02-20 17:32:05 +01:00
|
|
|
capabilities = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "Lua code that modifies inplace the `capabilities` table.";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
setupWrappers = mkOption {
|
|
|
|
type = with types; listOf (functionTo str);
|
|
|
|
description = "Code to be run to wrap the setup args. Takes in an argument containing the previous results, and returns a new string of code.";
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2022-01-09 23:00:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
preConfig = mkOption {
|
2021-11-23 15:39:57 +01:00
|
|
|
type = types.lines;
|
2022-01-09 23:00:19 +00:00
|
|
|
description = "Code to be run before loading the LSP. Useful for requiring plugins";
|
2021-11-23 15:39:57 +01:00
|
|
|
default = "";
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
|
|
|
postConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "Code to be run after loading the LSP. This is an internal option";
|
|
|
|
default = "";
|
|
|
|
};
|
2021-02-01 15:54:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
runWrappers = wrappers: s:
|
|
|
|
if wrappers == []
|
|
|
|
then s
|
|
|
|
else (head wrappers) (runWrappers (tail wrappers) s);
|
|
|
|
in
|
2022-09-18 11:19:23 +01:00
|
|
|
mkIf cfg.enable {
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [pkgs.vimPlugins.nvim-lspconfig];
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2023-03-14 15:22:56 +01:00
|
|
|
maps.normal = let
|
|
|
|
diagnosticMaps =
|
|
|
|
mapAttrs
|
|
|
|
(key: action: {
|
|
|
|
silent = cfg.keymaps.silent;
|
|
|
|
action = "vim.diagnostic.${action}";
|
|
|
|
lua = true;
|
|
|
|
})
|
|
|
|
cfg.keymaps.diagnostic;
|
|
|
|
|
|
|
|
lspBuf =
|
|
|
|
mapAttrs
|
|
|
|
(key: action: {
|
|
|
|
silent = cfg.keymaps.silent;
|
|
|
|
action = "vim.lsp.buf.${action}";
|
|
|
|
lua = true;
|
|
|
|
})
|
|
|
|
cfg.keymaps.lspBuf;
|
|
|
|
in
|
|
|
|
mkMerge [
|
|
|
|
diagnosticMaps
|
|
|
|
lspBuf
|
|
|
|
];
|
|
|
|
|
2021-02-01 15:54:53 +00:00
|
|
|
# Enable all LSP servers
|
|
|
|
extraConfigLua = ''
|
|
|
|
-- LSP {{{
|
2022-01-09 23:00:19 +00:00
|
|
|
do
|
|
|
|
${cfg.preConfig}
|
2023-02-20 17:32:05 +01:00
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
local __lspServers = ${helpers.toLuaObject cfg.enabledServers}
|
2022-12-05 09:49:37 +07:00
|
|
|
local __lspOnAttach = function(client, bufnr)
|
2022-01-09 23:00:19 +00:00
|
|
|
${cfg.onAttach}
|
|
|
|
end
|
2023-02-20 17:32:05 +01:00
|
|
|
local __lspCapabilities = function()
|
|
|
|
capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
|
|
|
|
${cfg.capabilities}
|
|
|
|
|
|
|
|
return capabilities
|
|
|
|
end
|
2022-01-09 23:00:19 +00:00
|
|
|
|
|
|
|
local __setup = ${runWrappers cfg.setupWrappers "{
|
2023-02-20 17:32:05 +01:00
|
|
|
on_attach = __lspOnAttach,
|
|
|
|
capabilities = __lspCapabilities()
|
2022-01-09 23:00:19 +00:00
|
|
|
}"}
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
for i,server in ipairs(__lspServers) do
|
|
|
|
if type(server) == "string" then
|
|
|
|
require('lspconfig')[server].setup(__setup)
|
|
|
|
else
|
|
|
|
local options = ${runWrappers cfg.setupWrappers "server.extraOptions"}
|
2022-10-22 22:15:03 +01:00
|
|
|
|
|
|
|
if options == nil then
|
|
|
|
options = __setup
|
|
|
|
else
|
|
|
|
options = vim.tbl_extend("keep", options, __setup)
|
|
|
|
end
|
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
require('lspconfig')[server.name].setup(options)
|
|
|
|
end
|
2021-02-01 15:54:53 +00:00
|
|
|
end
|
2023-01-21 19:52:56 +01:00
|
|
|
|
|
|
|
${cfg.postConfig}
|
2021-02-01 15:54:53 +00:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|