74 lines
1.7 KiB
Nix
74 lines
1.7 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
inherit (lib.nix2lua) pipe pipe1 var set call;
|
|
cfg = config.plugins.language-server.lspconfig;
|
|
in
|
|
{
|
|
options.plugins.language-server.lspconfig = with lib; {
|
|
enable = mkEnableOption "lspconfig";
|
|
|
|
package = mkPackageOption pkgs.vimPlugins "nvim-lspconfig" { };
|
|
|
|
serverSettings = mkOption {
|
|
type = with types; attrsOf attrs;
|
|
default = { };
|
|
description = ''
|
|
Server-specific settings.
|
|
|
|
`:help lspconfig-setup`
|
|
'';
|
|
};
|
|
|
|
defaultServerSettings = mkOption {
|
|
type = with types; nullOr attrs;
|
|
default = null;
|
|
};
|
|
|
|
keymap.set = mkOption {
|
|
type = with types; listOf keymap;
|
|
default = [ ];
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
fn.lspconfig-on-attach = {
|
|
args = [ "event" ];
|
|
content = { event }: {
|
|
vim.keymap.set = map
|
|
(attrs: attrs // { buffer = pipe1 event (var "buf"); })
|
|
cfg.keymap.set;
|
|
};
|
|
};
|
|
|
|
vim.augroup.user-lsp-config = {
|
|
event = "LspAttach";
|
|
callback = config.fn.lspconfig-on-attach.lambda;
|
|
};
|
|
|
|
plugin.nvim-lspconfig = rec {
|
|
name = "lspconfig";
|
|
varName = name;
|
|
package = cfg.package;
|
|
beforeSetup =
|
|
let varDefaultConfig = var "${varName}.util.default_config"; in
|
|
lib.optional (cfg.defaultServerSettings != null) (set
|
|
varDefaultConfig
|
|
(call "vim.tbl_extend" [
|
|
"force"
|
|
varDefaultConfig
|
|
cfg.defaultServerSettings
|
|
])
|
|
);
|
|
afterSetup = lib.mapAttrsToList
|
|
(ls: lsSettings:
|
|
pipe [
|
|
(var varName)
|
|
(var ls)
|
|
(call "setup" lsSettings)
|
|
]
|
|
)
|
|
cfg.serverSettings;
|
|
};
|
|
};
|
|
}
|