fix(nvim): Translate augroups and autocmds to nixvim

This commit is contained in:
Jalil David Salamé Messina 2024-03-02 21:04:02 +01:00
parent 8ea1f67f07
commit b2b9477041
Signed by: jalil
GPG key ID: F016B9E770737A0B
2 changed files with 81 additions and 72 deletions

View file

@ -1,93 +1,102 @@
{ {
highlightOnYank.name = "highlightOnYank"; autoGroups."highlightOnYank" = { };
highlightOnYank.autocmds = [ autoGroups."runLinter" = { };
autoGroups."lspConfig" = { };
autoGroups."restoreCursorPosition" = { };
autoCmd = [
{ {
group = "highlightOnYank";
event = "TextYankPost"; event = "TextYankPost";
pattern = "*"; pattern = "*";
luaCallback = '' callback = {
vim.highlight.on_yank { __raw = ''
higroup = ( function()
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch' vim.highlight.on_yank {
), higroup = (
timeout = 200, vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
} ),
''; timeout = 200,
}
end
'';
};
} }
];
runLinter.name = "runLinter";
runLinter.autocmds = [
{ {
group = "runLinter";
event = "BufWritePost"; event = "BufWritePost";
pattern = "*"; pattern = "*";
luaCallback = '' callback = {
require("lint").try_lint() __raw = ''
''; require("lint").try_lint()
'';
};
} }
];
restoreCursorPosition.name = "restoreCursorPosition";
restoreCursorPosition.autocmds = [
{ {
group = "restoreCursorPosition";
event = "BufReadPost"; event = "BufReadPost";
pattern = "*"; pattern = "*";
luaCallback = '' callback = {
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then __raw = ''
vim.cmd [[execute "normal! g'\""]] function()
end 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"; event = "LspAttach";
pattern = "*"; pattern = "*";
luaCallback = callback =
let let
opts = "noremap = true, buffer = bufnr"; opts = "noremap = true, buffer = bufnr";
in in
'' {
local bufnr = opts.buf __raw = ''
local client = vim.lsp.get_client_by_id(opts.data.client_id) function(opts)
local capabilities = client.server_capabilities local bufnr = opts.buf
-- Set Omnifunc if supported local client = vim.lsp.get_client_by_id(opts.data.client_id)
if capabilities.completionProvider then local capabilities = client.server_capabilities
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc" -- Set Omnifunc if supported
end if capabilities.completionProvider then
-- Enable inlay hints if supported vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
if capabilities.inlayHintProvider then end
vim.lsp.inlay_hint.enable(bufnr, true) -- Enable inlay hints if supported
end if capabilities.inlayHintProvider then
vim.keymap.set('n', -- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless vim.lsp.inlay_hint.enable(bufnr, true)
'<space>ht', end
function() vim.keymap.set('n', -- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless
vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled()) '<space>ht',
end, function()
{ desc = '[H]ints [T]oggle', ${opts} } vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled())
) end,
-- Enable hover if supported { desc = '[H]ints [T]oggle', ${opts} }
if capabilities.hoverProvider then )
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', ${opts} }) -- Enable hover if supported
end if capabilities.hoverProvider then
-- Enable rename if supported vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', ${opts} })
if capabilities.renameProvider then end
vim.keymap.set('n', '<leader>r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} }) -- Enable rename if supported
end if capabilities.renameProvider then
-- Enable code actions if supported vim.keymap.set('n', '<leader>r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} })
if capabilities.codeActionProvider then end
vim.keymap.set({ 'n', 'v' }, '<leader>fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} }) -- Enable code actions if supported
end if capabilities.codeActionProvider then
-- Enable formatting if supported vim.keymap.set({ 'n', 'v' }, '<leader>fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} })
if capabilities.documentFormattingProvider then end
vim.keymap.set('n', '<leader>w', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Buffer', ${opts} }) -- Enable formatting if supported
end if capabilities.documentFormattingProvider then
-- Other keybinds vim.keymap.set('n', '<leader>w', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Buffer', ${opts} })
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} }) end
vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} }) -- Other keybinds
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} }) 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
'';
};
} }
]; ];
} }

View file

@ -38,8 +38,8 @@ in
# Enable local configuration :h 'exrc' # Enable local configuration :h 'exrc'
options.exrc = true; # safe since nvim 0.9 options.exrc = true; # safe since nvim 0.9
plugins = import ./plugins; plugins = import ./plugins;
augroups = import ./augroups.nix;
keymaps = import ./mappings.nix; keymaps = import ./mappings.nix;
inherit (import ./augroups.nix) autoGroups autoCmd;
extraPlugins = extraPlugins =
(with pkgs.vimExtraPlugins; [ (with pkgs.vimExtraPlugins; [
dressing-nvim dressing-nvim