aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/testutil.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-08-11 09:27:48 +0100
committerLewis Russell <me@lewisr.dev>2024-09-21 16:04:09 +0100
commite5c174421df3872df0dd3a676609d1e74dfef6a9 (patch)
tree39354b9db7b9f3ccb9145f52d11574baa4508951 /test/functional/plugin/lsp/testutil.lua
parenta19e89022d8b72ee92bb974100b497f1c79b7765 (diff)
downloadrneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.tar.gz
rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.tar.bz2
rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.zip
test: support upvalues in exec_lua
Diffstat (limited to 'test/functional/plugin/lsp/testutil.lua')
-rw-r--r--test/functional/plugin/lsp/testutil.lua109
1 files changed, 51 insertions, 58 deletions
diff --git a/test/functional/plugin/lsp/testutil.lua b/test/functional/plugin/lsp/testutil.lua
index f60d111f87..a36cbac568 100644
--- a/test/functional/plugin/lsp/testutil.lua
+++ b/test/functional/plugin/lsp/testutil.lua
@@ -108,61 +108,55 @@ M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua'
M.fake_lsp_logfile = 'Xtest-fake-lsp.log'
local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
- exec_lua(
- function(test_name0, fake_lsp_code0, fake_lsp_logfile0, timeout, options0, settings0)
- _G.lsp = require('vim.lsp')
- _G.TEST_RPC_CLIENT_ID = _G.lsp.start_client {
- cmd_env = {
- NVIM_LOG_FILE = fake_lsp_logfile0,
- NVIM_LUA_NOTRACK = '1',
- NVIM_APPNAME = 'nvim_lsp_test',
- },
- cmd = {
- vim.v.progpath,
- '-l',
- fake_lsp_code0,
- test_name0,
- tostring(timeout),
- },
- handlers = setmetatable({}, {
- __index = function(_t, _method)
- return function(...)
- return vim.rpcrequest(1, 'handler', ...)
- end
- end,
- }),
- workspace_folders = {
- {
- uri = 'file://' .. vim.uv.cwd(),
- name = 'test_folder',
- },
- },
- before_init = function(_params, _config)
- vim.schedule(function()
- vim.rpcrequest(1, 'setup')
- end)
- end,
- on_init = function(client, result)
- _G.TEST_RPC_CLIENT = client
- vim.rpcrequest(1, 'init', result)
+ exec_lua(function(fake_lsp_code, fake_lsp_logfile, timeout)
+ options = options or {}
+ settings = settings or {}
+ _G.lsp = require('vim.lsp')
+ _G.TEST_RPC_CLIENT_ID = _G.lsp.start_client {
+ cmd_env = {
+ NVIM_LOG_FILE = fake_lsp_logfile,
+ NVIM_LUA_NOTRACK = '1',
+ NVIM_APPNAME = 'nvim_lsp_test',
+ },
+ cmd = {
+ vim.v.progpath,
+ '-l',
+ fake_lsp_code,
+ test_name,
+ tostring(timeout),
+ },
+ handlers = setmetatable({}, {
+ __index = function(_t, _method)
+ return function(...)
+ return vim.rpcrequest(1, 'handler', ...)
+ end
end,
- flags = {
- allow_incremental_sync = options0.allow_incremental_sync or false,
- debounce_text_changes = options0.debounce_text_changes or 0,
+ }),
+ workspace_folders = {
+ {
+ uri = 'file://' .. vim.uv.cwd(),
+ name = 'test_folder',
},
- settings = settings0,
- on_exit = function(...)
- vim.rpcnotify(1, 'exit', ...)
- end,
- }
- end,
- test_name,
- M.fake_lsp_code,
- M.fake_lsp_logfile,
- timeout_ms or 1e3,
- options or {},
- settings or {}
- )
+ },
+ before_init = function(_params, _config)
+ vim.schedule(function()
+ vim.rpcrequest(1, 'setup')
+ end)
+ end,
+ on_init = function(client, result)
+ _G.TEST_RPC_CLIENT = client
+ vim.rpcrequest(1, 'init', result)
+ end,
+ flags = {
+ allow_incremental_sync = options.allow_incremental_sync or false,
+ debounce_text_changes = options.debounce_text_changes or 0,
+ },
+ settings = settings,
+ on_exit = function(...)
+ vim.rpcnotify(1, 'exit', ...)
+ end,
+ }
+ end, M.fake_lsp_code, M.fake_lsp_logfile, timeout_ms or 1e3)
end
--- @class test.lsp.Config
@@ -193,13 +187,12 @@ function M.test_rpc_server(config)
-- Otherwise I would just return the value here.
return function(...)
return exec_lua(function(...)
- local name0 = ...
- if type(_G.TEST_RPC_CLIENT[name0]) == 'function' then
- return _G.TEST_RPC_CLIENT[name0](select(2, ...))
+ if type(_G.TEST_RPC_CLIENT[name]) == 'function' then
+ return _G.TEST_RPC_CLIENT[name](...)
else
- return _G.TEST_RPC_CLIENT[name0]
+ return _G.TEST_RPC_CLIENT[name]
end
- end, name, ...)
+ end, ...)
end
end,
})