2024-11-06 22:26:21 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
helpers,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2024-07-03 23:58:26 +02:00
|
|
|
let
|
2024-06-21 06:30:18 +02:00
|
|
|
inherit (helpers) mkRaw;
|
2024-11-06 22:26:21 +01:00
|
|
|
cfg = config.jhome.nvim;
|
|
|
|
dev = cfg.dev.enable;
|
2024-07-03 23:58:26 +02:00
|
|
|
in
|
|
|
|
{
|
2024-06-23 14:32:47 +02:00
|
|
|
config = {
|
|
|
|
autoGroups = {
|
2024-07-03 23:58:26 +02:00
|
|
|
"highlightOnYank" = { };
|
|
|
|
"lspConfig" = { };
|
|
|
|
"restoreCursorPosition" = { };
|
2024-11-20 21:57:58 +01:00
|
|
|
"terminalConfig" = { };
|
2024-06-23 14:32:47 +02:00
|
|
|
};
|
2024-11-06 22:26:21 +01:00
|
|
|
autoCmd =
|
|
|
|
[
|
2024-11-20 21:57:58 +01:00
|
|
|
{
|
|
|
|
group = "terminalConfig";
|
|
|
|
event = "TermOpen";
|
|
|
|
pattern = "*";
|
|
|
|
callback =
|
|
|
|
# lua
|
|
|
|
mkRaw ''
|
|
|
|
function(args)
|
|
|
|
vim.wo.number = false
|
|
|
|
vim.wo.relativenumber = false
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
}
|
2024-11-06 22:26:21 +01:00
|
|
|
{
|
|
|
|
group = "highlightOnYank";
|
|
|
|
event = "TextYankPost";
|
|
|
|
pattern = "*";
|
|
|
|
callback =
|
|
|
|
mkRaw
|
|
|
|
# lua
|
|
|
|
''
|
|
|
|
function()
|
|
|
|
vim.highlight.on_yank {
|
|
|
|
higroup = (
|
|
|
|
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
|
|
|
|
),
|
|
|
|
timeout = 200,
|
|
|
|
}
|
2024-07-03 23:58:26 +02:00
|
|
|
end
|
2024-11-06 22:26:21 +01:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
group = "restoreCursorPosition";
|
|
|
|
event = "BufReadPost";
|
|
|
|
pattern = "*";
|
|
|
|
callback =
|
|
|
|
mkRaw
|
|
|
|
# lua
|
|
|
|
''
|
|
|
|
function()
|
|
|
|
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
|
|
|
|
vim.cmd [[execute "normal! g'\""]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
]
|
|
|
|
++ lib.optional dev {
|
2024-06-23 14:32:47 +02:00
|
|
|
group = "lspConfig";
|
|
|
|
event = "LspAttach";
|
|
|
|
pattern = "*";
|
2024-07-03 23:58:26 +02:00
|
|
|
callback =
|
|
|
|
let
|
|
|
|
opts = "noremap = true, buffer = bufnr";
|
|
|
|
in
|
2024-07-02 09:29:44 +02:00
|
|
|
mkRaw
|
2024-07-03 23:58:26 +02:00
|
|
|
# lua
|
|
|
|
''
|
|
|
|
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()
|
|
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({bufnr = 0}), { bufnr = 0 })
|
|
|
|
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} })
|
|
|
|
end
|
|
|
|
-- Enable formatting if supported
|
|
|
|
if capabilities.documentFormattingProvider then
|
|
|
|
vim.keymap.set('n', '<leader>w', function() require("conform").format({ lsp_fallback = 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} })
|
2024-06-23 14:32:47 +02:00
|
|
|
end
|
2024-07-03 23:58:26 +02:00
|
|
|
'';
|
2024-11-06 22:26:21 +01:00
|
|
|
};
|
2024-06-23 14:32:47 +02:00
|
|
|
};
|
2024-06-22 19:25:51 +02:00
|
|
|
}
|