From cbd5f7de5e93cf501526cb64e64b1d4936fe9c45 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 13 May 2025 18:37:05 +0100 Subject: [PATCH] modules/lsp/onAttach: fix `bufnr` and document `event` arg `:h event-args`: https://neovim.io/doc/user/api.html#event-args `:h LspAttach`: https://neovim.io/doc/user/lsp.html#LspAttach Fixes #3319 --- modules/lsp/on-attach.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/lsp/on-attach.nix b/modules/lsp/on-attach.nix index 396a16d7..202d8d91 100644 --- a/modules/lsp/on-attach.nix +++ b/modules/lsp/on-attach.nix @@ -29,14 +29,25 @@ in { event = "LspAttach"; group = "nixvim_lsp_on_attach"; + # `event` is documented in `:h event-args`: + # • id: (number) autocommand id + # • event: (string) name of the triggered event + # • group: (number|nil) autocommand group id, if any + # • file: (string) (not expanded to a full path) + # • match: (string) (expanded to a full path) + # • buf: (number) + # • data: (any) arbitrary data passed from `:h nvim_exec_autocmds()` + # see `:h LspAttach` + # + # `:h event-args`: https://neovim.io/doc/user/api.html#event-args + # `:h LspAttach`: https://neovim.io/doc/user/lsp.html#LspAttach callback = lib.nixvim.mkRaw '' - function(args) + function(event) do -- client and bufnr are supplied to the builtin `on_attach` callback, -- so make them available in scope for our global `onAttach` impl - local client = vim.lsp.get_client_by_id(args.data.client_id) - local bufnr = args.bufnr - + local client = vim.lsp.get_client_by_id(event.data.client_id) + local bufnr = event.buf ${cfg.onAttach} end end