fix(eval): properly support checking v:lua function in exists() (#27124)

This commit is contained in:
Raphael 2024-01-22 16:04:50 +08:00 committed by GitHub
parent e68decab03
commit 12d123959f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 13 deletions

View File

@ -1369,6 +1369,7 @@ exists({expr}) *exists()*
echo exists("*strftime")
echo exists("*s:MyFunc")
echo exists("*MyFunc")
echo exists("*v:lua.Func")
echo exists("bufcount")
echo exists(":Make")
echo exists("#CursorHold")

View File

@ -1709,6 +1709,7 @@ function vim.fn.exepath(expr) end
--- echo exists("*strftime")
--- echo exists("*s:MyFunc")
--- echo exists("*MyFunc")
--- echo exists("*v:lua.Func")
--- echo exists("bufcount")
--- echo exists(":Make")
--- echo exists("#CursorHold")

View File

@ -2202,6 +2202,7 @@ M.funcs = {
echo exists("*strftime")
echo exists("*s:MyFunc")
echo exists("*MyFunc")
echo exists("*v:lua.Func")
echo exists("bufcount")
echo exists(":Make")
echo exists("#CursorHold")

View File

@ -1726,7 +1726,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
n = false; // Trailing garbage.
}
} else if (*p == '*') { // Internal or user defined function.
n = function_exists(p + 1, false);
n = strncmp(p, "*v:lua.", 7) == 0 ? nlua_func_exists(p + 7) : function_exists(p + 1, false);
} else if (*p == ':') {
n = cmd_exists(p + 1);
} else if (*p == '#') {
@ -1735,8 +1735,6 @@ static void f_exists(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} else {
n = au_exists(p + 1);
}
} else if (strncmp(p, "v:lua.", 6) == 0 && nlua_func_exists(p + 6)) {
n = true;
} else { // Internal variable.
n = var_exists(p);
}

View File

@ -4055,18 +4055,18 @@ describe('Vimscript function exists()', function()
1,
exec_lua [[
_G.test = function() print("hello") end
return vim.fn.exists('v:lua.test')
return vim.fn.exists('*v:lua.test')
]]
)
eq(1, fn.exists('v:lua.require("mpack").decode'))
eq(1, fn.exists("v:lua.require('mpack').decode"))
eq(1, fn.exists('v:lua.require"mpack".decode'))
eq(1, fn.exists("v:lua.require'mpack'.decode"))
eq(1, fn.exists("v:lua.require('vim.lsp').start"))
eq(1, fn.exists('v:lua.require"vim.lsp".start'))
eq(1, fn.exists("v:lua.require'vim.lsp'.start"))
eq(0, fn.exists("v:lua.require'vim.lsp'.unknown"))
eq(0, fn.exists('v:lua.?'))
eq(1, fn.exists('*v:lua.require("mpack").decode'))
eq(1, fn.exists("*v:lua.require('mpack').decode"))
eq(1, fn.exists('*v:lua.require"mpack".decode'))
eq(1, fn.exists("*v:lua.require'mpack'.decode"))
eq(1, fn.exists("*v:lua.require('vim.lsp').start"))
eq(1, fn.exists('*v:lua.require"vim.lsp".start'))
eq(1, fn.exists("*v:lua.require'vim.lsp'.start"))
eq(0, fn.exists("*v:lua.require'vim.lsp'.unknown"))
eq(0, fn.exists('*v:lua.?'))
end)
end)