mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
Merge pull request #13875 from smolck/vim_fn_error_on_api
vim.fn: throw error when trying to use API function
This commit is contained in:
@@ -263,9 +263,16 @@ end
|
||||
-- vim.fn.{func}(...)
|
||||
vim.fn = setmetatable({}, {
|
||||
__index = function(t, key)
|
||||
local function _fn(...)
|
||||
local _fn
|
||||
if vim.api[key] ~= nil then
|
||||
_fn = function()
|
||||
error(string.format("Tried to call API function with vim.fn: use vim.api.%s instead", key))
|
||||
end
|
||||
else
|
||||
_fn = function(...)
|
||||
return vim.call(key, ...)
|
||||
end
|
||||
end
|
||||
t[key] = _fn
|
||||
return _fn
|
||||
end
|
||||
|
@@ -715,6 +715,11 @@ describe('lua stdlib', function()
|
||||
eq({false, 'Vim:E714: List required'}, exec_lua([[return {pcall(vim.fn.add, "aa", "bb")}]]))
|
||||
end)
|
||||
|
||||
it('vim.fn should error when calling API function', function()
|
||||
eq('Error executing lua: vim.lua:0: Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead',
|
||||
pcall_err(exec_lua, "vim.fn.nvim_get_current_line()"))
|
||||
end)
|
||||
|
||||
it('vim.rpcrequest and vim.rpcnotify', function()
|
||||
exec_lua([[
|
||||
chan = vim.fn.jobstart({'cat'}, {rpc=true})
|
||||
|
Reference in New Issue
Block a user