echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.47k stars 175 forks source link

fix(statusline)!: make compute_attached_lsp() depend only number of attached client #907

Closed xuanduc987 closed 1 month ago

xuanduc987 commented 1 month ago

H.get_buf_lsp_clients will return a map of client_id:client. So if we handle it as array, there could be hole in it, and table.concat will fail with "invalid value (nil) at index [i] in table for 'concat'".

echasnovski commented 1 month ago

Thanks for the PR!

Do you have any reproducible example of when you encounter the error? Documentation of any core functions used in H.get_buf_lsp_clients() says that it returns "list" (a.k.a. array without holes).

I am not objecting the change per se, as it is cleaner. But having reproducible example will mean the need to add a test.

xuanduc987 commented 1 month ago

I'm still on neovim 0.9.4, so H.get_buf_lsp_clients() will call vim.lsp.buf_get_clients (returns a map) instead of vim.lsp.get_clients (returns a list)

I've just tried to change from vim to neovim several days before, so I still don't understand my whole lsp server setting (seems to auto configured with mason?). But I think if we attach several different lsp server for the same file type, then the bug will show up almost surely on neovim version < 0.10

echasnovski commented 1 month ago

Yeah, I missed that 'mini.statusline' uses vim.lsp.buf_get_clients() which indeed returns a map.

I've merged this in a temporary branch to polish a bit.

Edit: This should now be a part of main. Thanks for the quick noticing and fix!