Description
Field | Description |
---|---|
Module | lsp |
Nixpkgs | unstable |
Home Manager | not used |
I'm using a standalone flake
- I have read the FAQ and my bug is not listed there.
Description
In the lsp module we have this:
nixvim/modules/lsp/on-attach.nix
Lines 28 to 47 in ff0ccdf
If I understand correctly, when using lsp.onAttach, we are allowed to refer to client and bufnr in the Lua code. However, I believe the assignment:
local bufnr = args.bufnr
is incorrect and should instead be:
local bufnr = args.buf
Reasoning
While testing a code that relied on bufnr, I encountered an error (sorry, I don't have the exact log anymore), which disappeared once I changed the code to use args.buf directly. The minimal reproducible example below reproduces the same error.
if you try using the minimal example below, you I get this error message:
Error Message
When using the current implementation:
Error detected while processing LspAttach Autocommands for "*":
Error executing lua callback: /nix/store/mf79j9pggfgjacsfynplb1ls5lvvsg92-init.lua:690: attempt to concatenate local 'bufnr' (a nil value)
If I remove the bufnr usage and print args.buf instead, the output is correct:
args.buf number is: 2
This confirms that args.buf is correctly populated while bufnr is nil.
Unless I’m misunderstanding something (which is very possible), this seems like a small bug in the module.
Apologies if this report is missing anything or doesn't follow conventions. Reporting issues in other people's code is new to me. I'm happy to provide the original code I used if needed, but the minimal example below should be sufficient to reproduce the problem.
Minimal, Reproducible Example (MRE)
programs.nixvim = {
lsp.onAttach = ''
print("Buffer number is: " .. bufnr)
print("args.buf number is: " .. args.buf)
'';
}