62 lines
2.0 KiB
Nix
62 lines
2.0 KiB
Nix
{ nix2lua, vim, lib, ... }:
|
|
|
|
with nix2lua.lib;
|
|
|
|
let
|
|
defaultDiagnosticKeymaps = [
|
|
{ mode = "n"; bind = "<space>e"; command = raw "vim.diagnostic.open_float"; }
|
|
{ mode = "n"; bind = "[d"; command = raw "vim.diagnostic.goto_prev"; }
|
|
{ mode = "n"; bind = "]d"; command = raw "vim.diagnostic.goto_next"; }
|
|
{ mode = "n"; bind = "<space>q"; command = raw "vim.diagnostic.setloclist"; }
|
|
];
|
|
|
|
defaultKeymaps = [
|
|
{ mode = "n"; bind = "gD"; command = raw "vim.lsp.buf.declaration"; }
|
|
{ mode = "n"; bind = "gd"; command = raw "vim.lsp.buf.definition"; }
|
|
{ mode = "n"; bind = "K"; command = raw "vim.lsp.buf.hover"; }
|
|
{ mode = "n"; bind = "gi"; command = raw "vim.lsp.buf.implementation"; }
|
|
{ mode = "n"; bind = "gr"; command = raw "vim.lsp.buf.references"; }
|
|
{ mode = "n"; bind = "gy"; command = raw "vim.lsp.buf.type_definition"; }
|
|
{ mode = "n"; bind = "<C-k>"; command = raw "vim.lsp.buf.signature_help"; }
|
|
{ mode = "n"; bind = "<localleader>n"; command = raw "vim.lsp.buf.rename"; }
|
|
{ mode = [ "n" "v" ]; bind = "<localleader>a"; command = raw "vim.lsp.buf.code_action"; }
|
|
];
|
|
|
|
in
|
|
|
|
{ languageServerConfigs ? { }
|
|
, diagnosticKeymaps ? defaultDiagnosticKeymaps
|
|
, keymaps ? defaultKeymaps
|
|
}:
|
|
|
|
{
|
|
# dependencies
|
|
nvim-lspconfig = lib.flatten [
|
|
(local (set "lspconfig" (require "lspconfig")))
|
|
|
|
(lib.flip lib.mapAttrsToList languageServerConfigs (ls: lsConfigs:
|
|
pipe [
|
|
(var "lspconfig")
|
|
(var ls)
|
|
(call "setup"
|
|
(if builtins.isAttrs lsConfigs then lsConfigs
|
|
else { }))
|
|
]
|
|
))
|
|
|
|
(map vim.keymap.set diagnosticKeymaps)
|
|
|
|
(vim.api.nvim_create_autocmd "LspAttach" {
|
|
group = vim.api.nvim_create_augroup "UserLspConfig" { };
|
|
callback = lambda [ "ev" ]
|
|
(lib.flatten [
|
|
|
|
(local (set "opts" { buffer = pipe1 (var "ev") (var "buf"); }))
|
|
|
|
(lib.flip map keymaps (keymap:
|
|
vim.keymap.set (keymap // { opts = var "opts"; })))
|
|
]);
|
|
})
|
|
];
|
|
}
|