From 1d4a5cd18537d054a564ff19b9361120597d9dd7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 12 Dec 2023 19:06:22 +0800 Subject: 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(). --- test/functional/lua/vim_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/functional/lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 1ef214d611..403e9f6a12 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -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) -- cgit