Skip to content

modules/lsp/onAttach: fix bufnr and document event arg #3321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions modules/lsp/on-attach.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) <afile> (not expanded to a full path)
# • match: (string) <amatch> (expanded to a full path)
# • buf: (number) <abuf>
# • 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
Expand Down