feat(eval): exists() function supports checking v:lua functions (#26485)

Problem:  Vimscript function exists() can't check v:lua functions.
Solution: Add support for v:lua functions to exists().
This commit is contained in:
Raphael
2023-12-12 19:06:22 +08:00
committed by GitHub
parent e69834744b
commit 1d4a5cd185
4 changed files with 49 additions and 0 deletions

View File

@@ -3352,4 +3352,31 @@ describe('vim.keymap', function()
eq(1, exec_lua[[return GlobalCount]])
end)
it('exists() can check a lua function', function()
eq(true, exec_lua[[
_G.test = function() print("hello") end
return vim.fn.exists('v:lua.test') == 1
]])
eq(true, exec_lua[[
return vim.fn.exists('v:lua.require("mpack").decode') == 1
]])
eq(true, exec_lua[[
return vim.fn.exists("v:lua.require('vim.lsp').start") == 1
]])
eq(true, exec_lua[[
return vim.fn.exists('v:lua.require"vim.lsp".start') == 1
]])
eq(true, exec_lua[[
return vim.fn.exists("v:lua.require'vim.lsp'.start") == 1
]])
eq(false, exec_lua[[
return vim.fn.exists("v:lua.require'vim.lsp'.unknown") == 1
]])
end)
end)