2021-02-01 15:54:53 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.programs.nixvim.plugins.lsp;
|
|
|
|
helpers = (import ../helpers.nix { inherit lib; });
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
./clangd.nix
|
|
|
|
./rust-analyzer.nix
|
|
|
|
./rnix-lsp.nix
|
2021-11-23 15:41:03 +01:00
|
|
|
./pyright.nix
|
2022-01-17 15:02:08 -04:00
|
|
|
./zls.nix
|
2021-02-01 15:54:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.nixvim.plugins.lsp = {
|
|
|
|
enable = mkEnableOption "Enable neovim's built-in LSP";
|
|
|
|
|
|
|
|
enabledServers = mkOption {
|
|
|
|
type = with types; listOf (oneOf [str (submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The server's name";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = attrs;
|
|
|
|
description = "Extra options for the server";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})]);
|
|
|
|
description = "A list of enabled LSP servers. Don't use this directly.";
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
onAttach = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "A lua function to be run when a new LSP buffer is attached. The argument `client` is provided.";
|
|
|
|
default = "";
|
|
|
|
};
|
2021-11-23 15:39:57 +01:00
|
|
|
|
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.";
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
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 = "";
|
|
|
|
};
|
2021-02-01 15:54:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
config = let
|
|
|
|
runWrappers = wrappers: s:
|
|
|
|
if wrappers == [] then s
|
|
|
|
else (head wrappers) (runWrappers (tail wrappers) s);
|
|
|
|
in mkIf cfg.enable {
|
2021-02-01 15:54:53 +00:00
|
|
|
programs.nixvim = {
|
|
|
|
extraPlugins = [ pkgs.vimPlugins.nvim-lspconfig ];
|
|
|
|
|
|
|
|
# Enable all LSP servers
|
|
|
|
extraConfigLua = ''
|
|
|
|
-- LSP {{{
|
2022-01-09 23:00:19 +00:00
|
|
|
do
|
|
|
|
${cfg.preConfig}
|
|
|
|
local __lspServers = ${helpers.toLuaObject cfg.enabledServers}
|
|
|
|
local __lspOnAttach = function(client)
|
|
|
|
${cfg.onAttach}
|
|
|
|
end
|
|
|
|
|
|
|
|
local __setup = ${runWrappers cfg.setupWrappers "{
|
|
|
|
on_attach = __lspOnAttach
|
|
|
|
}"}
|
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"}
|
|
|
|
require('lspconfig')[server.name].setup(options)
|
|
|
|
end
|
2021-02-01 15:54:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|