nixeovim/modules/plugins/language-server/lspconfig.nix

69 lines
1.6 KiB
Nix
Raw Permalink Normal View History

2024-05-03 17:50:57 +03:00
{ config, lib, pkgs, ... }:
let
2024-05-09 02:28:24 +03:00
inherit (lib.nix2lua) pipe pipe1 var set call;
2024-05-03 17:50:57 +03:00
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 = { };
2024-05-09 02:28:24 +03:00
description = ''
Server-specific settings.
`:help lspconfig-setup`
'';
};
defaultServerSettings = mkOption {
type = with types; nullOr attrs;
default = null;
2024-05-03 17:50:57 +03:00
};
keymap.set = mkOption {
type = with types; listOf keymap;
default = [ ];
};
};
config = lib.mkIf cfg.enable {
fn.lspconfig-on-attach = {
args = [ "event" ];
2024-05-09 02:28:24 +03:00
content = { event }: {
2024-05-03 17:50:57 +03:00
vim.keymap.set = map
2024-05-10 15:56:17 +03:00
(attrs: attrs // { buffer = pipe1 event "buf"; })
2024-05-03 17:50:57 +03:00
cfg.keymap.set;
};
};
vim.augroup.user-lsp-config = {
event = "LspAttach";
callback = config.fn.lspconfig-on-attach.lambda;
};
2024-05-09 02:28:24 +03:00
plugin.nvim-lspconfig = rec {
2024-05-03 17:50:57 +03:00
name = "lspconfig";
2024-05-09 02:28:24 +03:00
varName = name;
2024-05-08 01:57:06 +03:00
package = cfg.package;
2024-05-09 02:28:24 +03:00
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
2024-05-10 15:56:17 +03:00
(ls: lsSettings: pipe [ varName ls (call "setup" lsSettings) ])
2024-05-03 17:50:57 +03:00
cfg.serverSettings;
};
};
}