modules: add lspconfig

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-22 10:53:56 +03:00
parent d888dcb9ba
commit 27fed7b39e
Signed by: pleshevskiy
GPG Key ID: 17041163DA10A9A2
4 changed files with 71 additions and 5 deletions

View File

@ -133,17 +133,16 @@
"lspsaga-nvim": {
"flake": false,
"locked": {
"lastModified": 1665291018,
"narHash": "sha256-jkoEP5jeIZDAK/27gpNTXtW10/Ev9nB5RqUahPhja2Y=",
"lastModified": 1713695968,
"narHash": "sha256-DBfYJqVJ2zgHY3OI0ZirRn7kr34d5Gj9hi0K+UvuUdg=",
"owner": "glepnir",
"repo": "lspsaga.nvim",
"rev": "f33bc99d0ed3ed691a58b3339decf4e1933c3f9e",
"rev": "f20985499cd8ff0fbbfe8e7c770428ef764fc3be",
"type": "github"
},
"original": {
"owner": "glepnir",
"repo": "lspsaga.nvim",
"rev": "f33bc99d0ed3ed691a58b3339decf4e1933c3f9e",
"type": "github"
}
},

View File

@ -71,7 +71,7 @@
# https://github.com/glepnir/lspsaga.nvim
lspsaga-nvim = {
url = "github:glepnir/lspsaga.nvim?rev=f33bc99d0ed3ed691a58b3339decf4e1933c3f9e";
url = "github:glepnir/lspsaga.nvim";
flake = false;
};
@ -257,6 +257,9 @@
hop-nvim = { };
telescope-nvim = { };
nvim-cmp = { };
lspconfig.languageServerConfigs = {
nil_ls = { };
};
};
plugins = with prev.nix2lua.lib; {

View File

@ -36,4 +36,7 @@ with nix2lua.lib;
*/
api.nvim_create_autocmd = event: opts:
call "vim.api.nvim_create_autocmd" [ event opts ];
api.nvim_create_augroup = name: opts:
call "vim.api.nvim_create_augroup" [ name opts ];
}

61
modules/lspconfig.nix Normal file
View File

@ -0,0 +1,61 @@
{ 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"; })))
]);
})
];
}