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 = { exclude_files = {
'test/_meta.lua',
'test/functional/fixtures/lua/syntax_error.lua', 'test/functional/fixtures/lua/syntax_error.lua',
'runtime/lua/vim/treesitter/_meta.lua', 'runtime/lua/vim/treesitter/_meta.lua',
'runtime/lua/vim/_meta/vimfn.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: ~ Parameters: ~
• {symbols} (`table`) DocumentSymbol[] or SymbolInformation[] • {symbols} (`table`) DocumentSymbol[] or SymbolInformation[]
• {bufnr} (`integer`) • {bufnr} (`integer?`)
============================================================================== ==============================================================================

View File

@ -140,3 +140,69 @@
--- @field sid string --- @field sid string
--- @field variables? table<string, any> --- @field variables? table<string, any>
--- @field version 1 --- @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. --- item.
--- ---
--- @param buf? integer|string --- @param buf? integer|string
--- @return any --- @return vim.fn.undotree.ret
function vim.fn.undotree(buf) end function vim.fn.undotree(buf) end
--- Remove second and succeeding copies of repeated adjacent --- 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) --- Computes size of float needed to show contents (with optional wrapping)
--- ---
---@param contents table of lines to show in window ---@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 --- - height of floating window
--- - width of floating window --- - width of floating window
--- - wrap_at character to wrap at for computing height --- - wrap_at character to wrap at for computing height
@ -1821,7 +1821,7 @@ end
--- Converts symbols to quickfix list items. --- Converts symbols to quickfix list items.
--- ---
---@param symbols table DocumentSymbol[] or SymbolInformation[] ---@param symbols table DocumentSymbol[] or SymbolInformation[]
---@param bufnr integer ---@param bufnr? integer
function M.symbols_to_items(symbols, bufnr) function M.symbols_to_items(symbols, bufnr)
local function _symbols_to_items(_symbols, _items, _bufnr) local function _symbols_to_items(_symbols, _items, _bufnr)
for _, symbol in ipairs(_symbols) do for _, symbol in ipairs(_symbols) do

View File

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

File diff suppressed because it is too large Load Diff