2024-02-16 20:10:20 +01:00
|
|
|
{
|
2024-05-17 18:50:01 +02:00
|
|
|
autoGroups = {
|
|
|
|
"highlightOnYank" = {};
|
|
|
|
"lspConfig" = {};
|
|
|
|
"restoreCursorPosition" = {};
|
|
|
|
};
|
2024-03-02 21:04:02 +01:00
|
|
|
autoCmd = [
|
2024-02-16 20:10:20 +01:00
|
|
|
{
|
2024-03-02 21:04:02 +01:00
|
|
|
group = "highlightOnYank";
|
2024-02-16 20:10:20 +01:00
|
|
|
event = "TextYankPost";
|
|
|
|
pattern = "*";
|
2024-03-02 21:04:02 +01:00
|
|
|
callback = {
|
|
|
|
__raw = ''
|
|
|
|
function()
|
|
|
|
vim.highlight.on_yank {
|
|
|
|
higroup = (
|
|
|
|
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
|
|
|
|
),
|
|
|
|
timeout = 200,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
2024-02-16 20:10:20 +01:00
|
|
|
}
|
|
|
|
{
|
2024-03-02 21:04:02 +01:00
|
|
|
group = "restoreCursorPosition";
|
2024-02-16 20:10:20 +01:00
|
|
|
event = "BufReadPost";
|
|
|
|
pattern = "*";
|
2024-03-02 21:04:02 +01:00
|
|
|
callback = {
|
|
|
|
__raw = ''
|
|
|
|
function()
|
|
|
|
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
|
|
|
|
vim.cmd [[execute "normal! g'\""]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
2024-02-16 20:10:20 +01:00
|
|
|
}
|
|
|
|
{
|
2024-03-02 21:04:02 +01:00
|
|
|
group = "lspConfig";
|
2024-02-16 20:10:20 +01:00
|
|
|
event = "LspAttach";
|
|
|
|
pattern = "*";
|
2024-05-04 20:57:33 +02:00
|
|
|
callback = let
|
|
|
|
opts = "noremap = true, buffer = bufnr";
|
|
|
|
in {
|
|
|
|
__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(true, { bufnr = bufnr })
|
|
|
|
end
|
|
|
|
-- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless
|
|
|
|
vim.keymap.set('n', '<space>ht', function()
|
2024-05-10 21:20:16 +02:00
|
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({bufnr = 0}), { bufnr = 0 })
|
2024-05-04 20:57:33 +02:00
|
|
|
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', '<leader>r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} })
|
|
|
|
end
|
|
|
|
-- Enable code actions if supported
|
|
|
|
if capabilities.codeActionProvider then
|
|
|
|
vim.keymap.set({ 'n', 'v' }, '<leader>fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} })
|
2024-03-02 21:04:02 +01:00
|
|
|
end
|
2024-05-04 20:57:33 +02:00
|
|
|
-- Enable formatting if supported
|
|
|
|
if capabilities.documentFormattingProvider then
|
2024-05-04 22:02:13 +02:00
|
|
|
vim.keymap.set('n', '<leader>w', function() require("conform").format({ lsp_fallback = true }) end, { desc = 'Format Buffer', ${opts} })
|
2024-05-04 20:57:33 +02:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
2024-02-16 20:10:20 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|