diff --git a/flake.lock b/flake.lock index b83ba03..e86ce64 100644 --- a/flake.lock +++ b/flake.lock @@ -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" } }, diff --git a/flake.nix b/flake.nix index bd64768..36ba702 100644 --- a/flake.nix +++ b/flake.nix @@ -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; { diff --git a/lib/vim.nix b/lib/vim.nix index 5af12e4..4a9e421 100644 --- a/lib/vim.nix +++ b/lib/vim.nix @@ -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 ]; } diff --git a/modules/lspconfig.nix b/modules/lspconfig.nix new file mode 100644 index 0000000..13af09e --- /dev/null +++ b/modules/lspconfig.nix @@ -0,0 +1,61 @@ +{ nix2lua, vim, lib, ... }: + +with nix2lua.lib; + +let + defaultDiagnosticKeymaps = [ + { mode = "n"; bind = "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 = "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 = ""; command = raw "vim.lsp.buf.signature_help"; } + { mode = "n"; bind = "n"; command = raw "vim.lsp.buf.rename"; } + { mode = [ "n" "v" ]; bind = "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"; }))) + ]); + }) + ]; +}