mirror of
https://github.com/neovim/neovim.git
synced 2025-11-22 10:06:33 +00:00
test: support upvalues in exec_lua
This commit is contained in:
committed by
Lewis Russell
parent
a19e89022d
commit
e5c174421d
@@ -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)
|
||||
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,
|
||||
on_init = function(client, result)
|
||||
_G.TEST_RPC_CLIENT = client
|
||||
vim.rpcrequest(1, 'init', result)
|
||||
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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user