lsp: call default_on_attach in LspAttach autocmd

This commit is contained in:
Ching Pei Yang 2025-09-26 00:01:30 +02:00
commit e1fd607e3f
No known key found for this signature in database
GPG key ID: B3841364253DC4C8

View file

@ -10,6 +10,8 @@
inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString;
inherit (lib.nvim.binds) addDescriptionsToMappings;
inherit (lib.nvim.dag) entryBefore;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.lsp;
usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable;
@ -23,7 +25,7 @@
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
mkBinding = binding: action:
if binding.value != null
then "vim.keymap.set('n', '${binding.value}', ${action}, {buffer=bufnr, noremap=true, silent=true, desc='${binding.description}'})"
then "vim.keymap.set('n', ${toLuaObject binding.value}, ${action}, {buffer=bufnr, noremap=true, silent=true, desc=${toLuaObject binding.description}})"
else "";
in {
config = mkIf cfg.enable {
@ -35,20 +37,26 @@ in {
augroups = [{name = augroup;}];
autocmds =
(optional cfg.inlayHints.enable {
group = augroup;
event = ["LspAttach"];
desc = "LSP on-attach enable inlay hints autocmd";
callback = mkLuaInline ''
function(event)
local bufnr = event.buf
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })
[
{
group = augroup;
event = ["LspAttach"];
desc = "LSP on-attach add keybinds, enable inlay hints, and other plugin integrations";
callback = mkLuaInline ''
function(event)
local bufnr = event.buf
local client = vim.lsp.get_client_by_id(event.data.client_id)
default_on_attach(client, bufnr)
${optionalString cfg.inlayHints.enable ''
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })
end
''}
end
end
'';
})
'';
}
]
++ (optional (!conformFormatOnSave) {
group = augroup;
event = ["BufWritePre"];
@ -87,7 +95,7 @@ in {
'';
});
pluginRC.lsp-setup = ''
pluginRC.lsp-setup = entryBefore ["autocmds"] ''
vim.g.formatsave = ${boolToString cfg.formatOnSave};
local attach_keymaps = function(client, bufnr)