From b2b947704134e9a495c9c52d57f9445ffba8fc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sat, 2 Mar 2024 21:04:02 +0100 Subject: [PATCH] fix(nvim): Translate augroups and autocmds to nixvim --- nvim/augroups.nix | 151 ++++++++++++++++++++++++---------------------- nvim/default.nix | 2 +- 2 files changed, 81 insertions(+), 72 deletions(-) diff --git a/nvim/augroups.nix b/nvim/augroups.nix index edfe0cc..d843dde 100644 --- a/nvim/augroups.nix +++ b/nvim/augroups.nix @@ -1,93 +1,102 @@ { - highlightOnYank.name = "highlightOnYank"; - highlightOnYank.autocmds = [ + autoGroups."highlightOnYank" = { }; + autoGroups."runLinter" = { }; + autoGroups."lspConfig" = { }; + autoGroups."restoreCursorPosition" = { }; + autoCmd = [ { + group = "highlightOnYank"; event = "TextYankPost"; pattern = "*"; - luaCallback = '' - vim.highlight.on_yank { - higroup = ( - vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch' - ), - timeout = 200, - } - ''; + callback = { + __raw = '' + function() + vim.highlight.on_yank { + higroup = ( + vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch' + ), + timeout = 200, + } + end + ''; + }; } - ]; - - runLinter.name = "runLinter"; - runLinter.autocmds = [ { + group = "runLinter"; event = "BufWritePost"; pattern = "*"; - luaCallback = '' - require("lint").try_lint() - ''; + callback = { + __raw = '' + require("lint").try_lint() + ''; + }; } - ]; - - restoreCursorPosition.name = "restoreCursorPosition"; - restoreCursorPosition.autocmds = [ { + group = "restoreCursorPosition"; event = "BufReadPost"; pattern = "*"; - luaCallback = '' - if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then - vim.cmd [[execute "normal! g'\""]] - end - ''; + callback = { + __raw = '' + function() + if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then + vim.cmd [[execute "normal! g'\""]] + end + end + ''; + }; } - ]; - - lspConfig.name = "lspConfig"; - lspConfig.autocmds = [ { + group = "lspConfig"; event = "LspAttach"; pattern = "*"; - luaCallback = + callback = let opts = "noremap = true, buffer = bufnr"; in - '' - local bufnr = opts.buf - local client = vim.lsp.get_client_by_id(opts.data.client_id) - local capabilities = client.server_capabilities - -- Set Omnifunc if supported - if capabilities.completionProvider then - vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc" - end - -- Enable inlay hints if supported - if capabilities.inlayHintProvider then - vim.lsp.inlay_hint.enable(bufnr, true) - end - vim.keymap.set('n', -- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless - 'ht', - function() - vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled()) - end, - { desc = '[H]ints [T]oggle', ${opts} } - ) - -- Enable hover if supported - if capabilities.hoverProvider then - vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', ${opts} }) - end - -- Enable rename if supported - if capabilities.renameProvider then - vim.keymap.set('n', 'r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} }) - end - -- Enable code actions if supported - if capabilities.codeActionProvider then - vim.keymap.set({ 'n', 'v' }, 'fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} }) - end - -- Enable formatting if supported - if capabilities.documentFormattingProvider then - vim.keymap.set('n', 'w', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Buffer', ${opts} }) - end - -- Other keybinds - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} }) - vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} }) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} }) - ''; + { + __raw = '' + function(opts) + local bufnr = opts.buf + local client = vim.lsp.get_client_by_id(opts.data.client_id) + local capabilities = client.server_capabilities + -- Set Omnifunc if supported + if capabilities.completionProvider then + vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc" + end + -- Enable inlay hints if supported + if capabilities.inlayHintProvider then + vim.lsp.inlay_hint.enable(bufnr, true) + end + vim.keymap.set('n', -- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless + 'ht', + function() + vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled()) + end, + { desc = '[H]ints [T]oggle', ${opts} } + ) + -- Enable hover if supported + if capabilities.hoverProvider then + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', ${opts} }) + end + -- Enable rename if supported + if capabilities.renameProvider then + vim.keymap.set('n', 'r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} }) + end + -- Enable code actions if supported + if capabilities.codeActionProvider then + vim.keymap.set({ 'n', 'v' }, 'fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} }) + end + -- Enable formatting if supported + if capabilities.documentFormattingProvider then + vim.keymap.set('n', 'w', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Buffer', ${opts} }) + end + -- Other keybinds + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} }) + vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} }) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} }) + end + ''; + }; } ]; } diff --git a/nvim/default.nix b/nvim/default.nix index cea576e..d5810fa 100644 --- a/nvim/default.nix +++ b/nvim/default.nix @@ -38,8 +38,8 @@ in # Enable local configuration :h 'exrc' options.exrc = true; # safe since nvim 0.9 plugins = import ./plugins; - augroups = import ./augroups.nix; keymaps = import ./mappings.nix; + inherit (import ./augroups.nix) autoGroups autoCmd; extraPlugins = (with pkgs.vimExtraPlugins; [ dressing-nvim