diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index e0bdbbc1e9..0763bbd329 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -2323,10 +2323,12 @@ bool nlua_func_exists(const char *lua_funcname) vim_snprintf(str, length, "return %s", lua_funcname); ADD_C(args, CSTR_AS_OBJ(str)); Error err = ERROR_INIT; - Object result = NLUA_EXEC_STATIC("return type(loadstring(...)()) =='function'", args, &err); + Object result = NLUA_EXEC_STATIC("return type(loadstring(...)()) == 'function'", args, &err); xfree(str); + api_clear_error(&err); if (result.type != kObjectTypeBoolean) { + api_free_object(result); return false; } return result.data.boolean; diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 403e9f6a12..509958bbde 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -3351,32 +3351,23 @@ 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) + +describe('Vimscript function exists()', function() + it('can check a lua function', function() + eq(1, exec_lua[[ + _G.test = function() print("hello") end + return vim.fn.exists('v:lua.test') + ]]) + + eq(1, funcs.exists('v:lua.require("mpack").decode')) + eq(1, funcs.exists("v:lua.require('mpack').decode")) + eq(1, funcs.exists('v:lua.require"mpack".decode')) + eq(1, funcs.exists("v:lua.require'mpack'.decode")) + eq(1, funcs.exists("v:lua.require('vim.lsp').start")) + eq(1, funcs.exists('v:lua.require"vim.lsp".start')) + eq(1, funcs.exists("v:lua.require'vim.lsp'.start")) + eq(0, funcs.exists("v:lua.require'vim.lsp'.unknown")) + eq(0, funcs.exists('v:lua.?')) + end) end) diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua index 462661e97f..f5c1b0f3c1 100644 --- a/test/functional/treesitter/fold_spec.lua +++ b/test/functional/treesitter/fold_spec.lua @@ -639,9 +639,7 @@ t2]]) {1:│}t1 | {1:│}^ | {1:+}{2:+-- 2 lines: # h2·····················}| - {3:~ }| - {3:~ }| - {3:~ }| + {3:~ }|*3 {4:-- INSERT --} | ]]} @@ -656,10 +654,7 @@ t2]]) {1:-}^t1 | {1:-}# h2 | {1:│}t2 | - {3:~ }| - {3:~ }| - {3:~ }| - {3:~ }| + {3:~ }|*4 1 line less; before #2 {MATCH:.*}| ]]} end)