Closed kdarkhan closed 1 year ago
This fixes the problem for many of us. I lost time because I didn't zero in on a problem with rust-tools right away and my search didn't find this PR or the issues that refer to it as soon as I would have liked. I'm including the error message in case it helps the next person find this more quickly.
Error executing vim.schedule lua callback: ...im/bundle/rust-tools.nvim/lua/rust-tools/inlay_hints.lua:216: bad argument
#1 to 'sub' (string expected, got table)
stack traceback:
[C]: in function 'sub'
...im/bundle/rust-tools.nvim/lua/rust-tools/inlay_hints.lua:216: in function 'render_line'
...im/bundle/rust-tools.nvim/lua/rust-tools/inlay_hints.lua:260: in function 'render'
...im/bundle/rust-tools.nvim/lua/rust-tools/inlay_hints.lua:170: in function 'handler'
...l/Cellar/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Why is this still an open issue?, please fix, it's so simple
just replace other_hints
to other_hints[1]
I fixed it manually, and I hate to waste debugging for 30 mins for something so simple as this.
---------------- How to fix ---------------------
go to the ~/.local/share/nvim/site/pack/packer/opt/rust-tools.nvim/lua/rust-tools/inlya_hints.lua
then on line 215
change the other_hints
to other_hints[1]
the function becomes
-- show other hints with commas and a thicc arrow
if not vim.tbl_isempty(other_hints) then
virt_text = virt_text .. opts.other_hints_prefix
for i, o_hint in ipairs(other_hints[1]) do --- <<<- this line just needed to be changed.
if string.sub(o_hint.label, 1, 2)== ": " then
virt_text = virt_text .. o_hint.label:sub(3)
else
virt_text = virt_text .. o_hint.label
end
if i ~= #other_hints then
virt_text = virt_text .. ", "
end
end
end
Is this repository still maintained?
Sorry I have been very busy with life but I'll try to find time to maintain the repo. PR looks good.
According to LSP spec, InlayHint.label can be either a string or an array. Previously,
rust-analyzer
was always returning strings. Most likely after this recent PR it started returning arrays.Based on my testing, it seems only inlay hints with
kind
1 are returning arrays but I am preemptively handlingkind
2 as well in case it changes in the future.