Draft: modules #1

Draft
pleshevskiy wants to merge 15 commits from modules into main
4 changed files with 71 additions and 5 deletions
Showing only changes of commit 27fed7b39e - Show all commits

View file

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

View file

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

View file

@ -36,4 +36,7 @@ with nix2lua.lib;
*/ */
api.nvim_create_autocmd = event: opts: api.nvim_create_autocmd = event: opts:
call "vim.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"; })))
]);
})
];
}