Instead of making a helpthread for my own problem here, I thought I’d title this as a general thread were people can ask questions and hopefully receive answers as well.
So I need to turn this thing in to Lua, but I’m new to Lua and have only copy pasted bramscript before.
AFAIK, I should be able to call coc#rpc#ready() with vim.fn['coc#rpc#ready'](), but what is index() here? I assume the first argument would be { 'vim', 'help' }, but what would &filetype be in Lua? I assume 'h '.expand() is not a thing in Lua (and the rest of the similar stuff in the else block)?
E: also, I have no idea what the s: is, but apparently it’s not functioning well anyway.
Instead of making a helpthread for my own problem here, I thought I’d title this as a general thread were people can ask questions and hopefully receive answers as well.
So I need to turn this thing in to Lua, but I’m new to Lua and have only copy pasted bramscript before.
AFAIK, I should be able to call
coc#rpc#ready()
withvim.fn['coc#rpc#ready']()
, but what isindex()
here? I assume the first argument would be{ 'vim', 'help' }
, but what would&filetype
be in Lua? I assume'h '.expand()
is not a thing in Lua (and the rest of the similar stuff in the else block)?E: also, I have no idea what the
s:
is, but apparently it’s not functioning well anyway.The function is taken from CoC’s example config: https://github.com/neoclide/coc.nvim
I don’t use CoC and I don’t know every Lua API function so this might be clunky, but the following works on my machine:
function _G.show_documentation() local ft = vim.bo.filetype local cword = vim.fn.expand('<cword>') if ft == 'help' or ft == 'vim' then vim.fn.execute('help ' .. cword) --[[ elseif vim.fn['coc#rpc#ready']() then vim.fn.call('CocActionAsync', {'doHover'}) ]] else vim.fn.execute(vim.o.keywordprg .. ' ' .. cword) end end vim.api.nvim_set_keymap('n', 'K', "<Cmd>call v:lua.show_documentation()<CR>", {noremap = true, silent = true})
Note that I commented out the elseif statement since I don’t have CoC and the function fails if it can’t call
coc#rpc#ready
.Thank you! I’m gonna study this well before I copy paste time around.
E: it works! Somehow the Lua version is easier to read and understand as well.
Glad to hear it! Had to go digging though the help pages to find out what expand() did in the original and how to get the word under the cursor in Lua