test(lsp): refactor and tidy

- Merge all the top level 'LSP' describe blocks
- Refactor text edit tests
- Fix typing errors
- Add linebreaks between tests
This commit is contained in:
Lewis Russell 2024-08-11 11:58:15 +01:00 committed by Lewis Russell
parent 8df6736ca1
commit 9b5ab66678
9 changed files with 441 additions and 331 deletions

View File

@ -42,6 +42,7 @@ globals = {
}
exclude_files = {
'test/_meta.lua',
'test/functional/fixtures/lua/syntax_error.lua',
'runtime/lua/vim/treesitter/_meta.lua',
'runtime/lua/vim/_meta/vimfn.lua',

View File

@ -2241,7 +2241,7 @@ symbols_to_items({symbols}, {bufnr}) *vim.lsp.util.symbols_to_items()*
Parameters: ~
• {symbols} (`table`) DocumentSymbol[] or SymbolInformation[]
• {bufnr} (`integer`)
• {bufnr} (`integer?`)
==============================================================================

View File

@ -140,3 +140,69 @@
--- @field sid string
--- @field variables? table<string, any>
--- @field version 1
--- @class vim.fn.undotree.entry
---
--- Undo sequence number. Same as what appears in
--- \|:undolist|.
--- @field seq integer
---
--- Timestamp when the change happened. Use
--- \|strftime()| to convert to something readable.
--- @field time integer
---
--- Only appears in the item that is the last one
--- that was added. This marks the last change
--- and where further changes will be added.
--- @field newhead? integer
---
--- Only appears in the item that is the last one
--- that was undone. This marks the current
--- position in the undo tree, the block that will
--- be used by a redo command. When nothing was
--- undone after the last change this item will
--- not appear anywhere.
--- @field curhead? integer
---
--- Only appears on the last block before a file
--- write. The number is the write count. The
--- first write has number 1, the last one the
--- "save_last" mentioned above.
--- @field save integer
---
--- Alternate entry. This is again a List of undo
--- blocks. Each item may again have an "alt"
--- item.
--- @field alt vim.fn.undotree.entry[]
--- @class vim.fn.undotree.ret
---
--- The highest undo sequence number used.
--- @field seq_last integer
---
--- The sequence number of the current position in
--- the undo tree. This differs from "seq_last"
--- when some changes were undone.
--- @field seq_cur integer
---
--- Time last used for |:earlier| and related
--- commands. Use |strftime()| to convert to
--- something readable.
--- @field time_cur integer
---
--- Number of the last file write. Zero when no
--- write yet.
--- @field save_last integer
---
--- Number of the current position in the undo
--- tree.
--- @field save_cur integer
---
--- Non-zero when the last undo block was synced.
--- This happens when waiting from input from the
--- user. See |undo-blocks|.
--- @field synced integer
---
--- A list of dictionaries with information about
--- undo blocks.
--- @field entries vim.fn.undotree.entry[]

View File

@ -10403,7 +10403,7 @@ function vim.fn.undofile(name) end
--- item.
---
--- @param buf? integer|string
--- @return any
--- @return vim.fn.undotree.ret
function vim.fn.undotree(buf) end
--- Remove second and succeeding copies of repeated adjacent

View File

@ -1442,7 +1442,7 @@ end
--- Computes size of float needed to show contents (with optional wrapping)
---
---@param contents table of lines to show in window
---@param opts table with optional fields
---@param opts? table with optional fields
--- - height of floating window
--- - width of floating window
--- - wrap_at character to wrap at for computing height
@ -1821,7 +1821,7 @@ end
--- Converts symbols to quickfix list items.
---
---@param symbols table DocumentSymbol[] or SymbolInformation[]
---@param bufnr integer
---@param bufnr? integer
function M.symbols_to_items(symbols, bufnr)
local function _symbols_to_items(_symbols, _items, _bufnr)
for _, symbol in ipairs(_symbols) do

View File

@ -12445,6 +12445,7 @@ M.funcs = {
]=],
name = 'undotree',
params = { { 'buf', 'integer|string' } },
returns = 'vim.fn.undotree.ret',
signature = 'undotree([{buf}])',
},
uniq = {

10
test/_meta.lua Normal file
View File

@ -0,0 +1,10 @@
--- @meta
do -- Mark block as optional
---Mark a test as placeholder.
---
---This will not fail or pass, it will simply be marked as "pending".
---@param name string
---@param block? fun()
function pending(name, block) end
end

View File

@ -21,8 +21,8 @@ function M.clear_notrace()
}
end
M.create_server_definition = [[
function _create_server(opts)
M.create_server_definition = function()
function _G._create_server(opts)
opts = opts or {}
local server = {}
server.messages = {}
@ -42,7 +42,7 @@ M.create_server_definition = [[
handler(method, params, callback)
elseif method == 'initialize' then
callback(nil, {
capabilities = opts.capabilities or {}
capabilities = opts.capabilities or {},
})
elseif method == 'shutdown' then
callback(nil, nil)
@ -54,7 +54,7 @@ M.create_server_definition = [[
function srv.notify(method, params)
table.insert(server.messages, {
method = method,
params = params
params = params,
})
if method == 'exit' then
dispatchers.on_exit(0, 15)
@ -74,7 +74,7 @@ M.create_server_definition = [[
return server
end
]]
end
-- Fake LSP server.
M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua'
@ -82,48 +82,53 @@ M.fake_lsp_logfile = 'Xtest-fake-lsp.log'
local function fake_lsp_server_setup(test_name, timeout_ms, options, settings)
exec_lua(
[=[
lsp = require('vim.lsp')
local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ...
TEST_RPC_CLIENT_ID = lsp.start_client {
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_logfile;
NVIM_LUA_NOTRACK = "1";
NVIM_APPNAME = "nvim_lsp_test";
};
NVIM_LOG_FILE = fake_lsp_logfile0,
NVIM_LUA_NOTRACK = '1',
NVIM_APPNAME = 'nvim_lsp_test',
},
cmd = {
vim.v.progpath, '-l', fake_lsp_code, test_name, tostring(timeout),
};
vim.v.progpath,
'-l',
fake_lsp_code0,
test_name0,
tostring(timeout),
},
handlers = setmetatable({}, {
__index = function(t, method)
__index = function(_t, _method)
return function(...)
return vim.rpcrequest(1, 'handler', ...)
end
end;
});
workspace_folders = {{
end,
}),
workspace_folders = {
{
uri = 'file://' .. vim.uv.cwd(),
name = 'test_folder',
}};
before_init = function(params, config)
},
},
before_init = function(_params, _config)
vim.schedule(function()
vim.rpcrequest(1, "setup")
vim.rpcrequest(1, 'setup')
end)
end,
on_init = function(client, result)
TEST_RPC_CLIENT = client
vim.rpcrequest(1, "init", result)
end;
_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;
allow_incremental_sync = options0.allow_incremental_sync or false,
debounce_text_changes = options0.debounce_text_changes or 0,
},
settings = settings0,
on_exit = function(...)
vim.rpcnotify(1, "exit", ...)
end;
vim.rpcnotify(1, 'exit', ...)
end,
}
]=],
end,
test_name,
M.fake_lsp_code,
M.fake_lsp_logfile,
@ -160,18 +165,14 @@ function M.test_rpc_server(config)
-- Workaround for not being able to yield() inside __index for Lua 5.1 :(
-- Otherwise I would just return the value here.
return function(...)
return exec_lua(
[=[
local name = ...
if type(TEST_RPC_CLIENT[name]) == 'function' then
return TEST_RPC_CLIENT[name](select(2, ...))
return exec_lua(function(...)
local name0 = ...
if type(_G.TEST_RPC_CLIENT[name0]) == 'function' then
return _G.TEST_RPC_CLIENT[name0](select(2, ...))
else
return TEST_RPC_CLIENT[name]
return _G.TEST_RPC_CLIENT[name0]
end
]=],
name,
...
)
end, name, ...)
end
end,
})

File diff suppressed because it is too large Load Diff