1

What is the most efficient way to call a Neovim function using Lua. I am able to call the sign_define Vim script function using the nvim_command procedure. I struggle with calling it with the nvim_call_function due to (assuming) converting the lua table to a Vim script dict.

-- Change default signcolumn signs for LSP

api.nvim_call_function('sign_define', {"LspDiagnosticsErrorSign", '{"text" : "", "texthl" : "LspDiagnosticsError"}'})

api.nvim_command('call sign_define("LspDiagnosticsWarningSign", {"text" : "", "texthl" : "LspDiagnosticsWarning"})')

Separately, I wonder if there may be errors due to lua's lack of Unicode support (stdlib).

3

It must be

vim.api.nvim_call_function("sign_define", {"LspDiagnosticsErrorSign",
    {text = "whatever", texthl = "LspDiagnosticsError"}})

as Lua has its own syntax for defining tables. Or, at least in 0.5, you can do

vim.fn.sign_define("LspDiagnosticsErrorSign",
    {text = "whatever", texthl = "LspDiagnosticsError"})

which looks a bit nicer.

Separately, I wonder if there may be errors due to lua's lack of Unicode support (stdlib).

Well, that depends on how the engine was built, but, yes, you may easily catch such sort of errors. For example, io.open() may succeed, but the name of a created file will look "funny", and so on. But at least Lua should not segfault.

2
  • 1
    kudos for using vim.fn – tkolleh Aug 24 '20 at 3:10
  • For any having troubles, LspDiagnosticsErrorSign to LspDiagnosticsSignError .. – Luca Trazzi Dec 14 '20 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.