diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-03-09 23:12:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 23:12:23 +0100 |
commit | e355cc8cc5c131e6df429107f321dd4a80c05065 (patch) | |
tree | b501607f219c9ec7de6ac4b1b36ca6615089789f | |
parent | 7c204af87aa74120a70db14b87c5e7c7096ae478 (diff) | |
parent | d1899bb5f40d9f6f0e4426b6e87a44b69e38b29f (diff) | |
download | rneovim-e355cc8cc5c131e6df429107f321dd4a80c05065.tar.gz rneovim-e355cc8cc5c131e6df429107f321dd4a80c05065.tar.bz2 rneovim-e355cc8cc5c131e6df429107f321dd4a80c05065.zip |
Merge pull request #13875 from smolck/vim_fn_error_on_api
vim.fn: throw error when trying to use API function
-rw-r--r-- | src/nvim/lua/vim.lua | 11 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 5 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index e13b9745a8..eb54ff28ee 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -263,8 +263,15 @@ end -- vim.fn.{func}(...) vim.fn = setmetatable({}, { __index = function(t, key) - local function _fn(...) - return vim.call(key, ...) + 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 diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e253db5297..9bf00b594b 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -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}) |