aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/completion_spec.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/completion_spec.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/completion_spec.lua')
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua99
1 files changed, 42 insertions, 57 deletions
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index d3796082fb..4df8d77d44 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -23,12 +23,10 @@ local function complete(line, candidates, lnum, server_boundary)
-- nvim_win_get_cursor returns 0 based column, line:find returns 1 based
local cursor_col = line:find('|') - 1
line = line:gsub('|', '')
- return exec_lua(
- [[
- local line, cursor_col, lnum, result, server_boundary = ...
+ return exec_lua(function(result)
local line_to_cursor = line:sub(1, cursor_col)
local client_start_boundary = vim.fn.match(line_to_cursor, '\\k*$')
- local items, new_server_boundary = require("vim.lsp.completion")._convert_results(
+ local items, new_server_boundary = require('vim.lsp.completion')._convert_results(
line,
lnum,
cursor_col,
@@ -36,19 +34,13 @@ local function complete(line, candidates, lnum, server_boundary)
client_start_boundary,
server_boundary,
result,
- "utf-16"
+ 'utf-16'
)
return {
items = items,
- server_start_boundary = new_server_boundary
+ server_start_boundary = new_server_boundary,
}
- ]],
- line,
- cursor_col,
- lnum,
- candidates,
- server_boundary
- )
+ end, candidates)
end
describe('vim.lsp.completion: item conversion', function()
@@ -483,13 +475,14 @@ describe('vim.lsp.completion: protocol', function()
before_each(function()
clear()
exec_lua(create_server_definition)
- exec_lua([[
+ exec_lua(function()
_G.capture = {}
+ --- @diagnostic disable-next-line:duplicate-set-field
vim.fn.complete = function(col, matches)
_G.capture.col = col
_G.capture.matches = matches
end
- ]])
+ end)
end)
after_each(clear)
@@ -497,32 +490,34 @@ describe('vim.lsp.completion: protocol', function()
--- @param completion_result lsp.CompletionList
--- @return integer
local function create_server(completion_result)
- return exec_lua(
- [[
- local result = ...
- local server = _create_server({
+ return exec_lua(function()
+ local server = _G._create_server({
capabilities = {
completionProvider = {
- triggerCharacters = { '.' }
- }
+ triggerCharacters = { '.' },
+ },
},
handlers = {
['textDocument/completion'] = function(_, _, callback)
- callback(nil, result)
- end
- }
+ callback(nil, completion_result)
+ end,
+ },
})
- bufnr = vim.api.nvim_get_current_buf()
+ local bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_buf(0, bufnr)
- return vim.lsp.start({ name = 'dummy', cmd = server.cmd, on_attach = function(client, bufnr)
- vim.lsp.completion.enable(true, client.id, bufnr, { convert = function(item)
- return { abbr = item.label:gsub('%b()', '')}
- end})
- end})
- ]],
- completion_result
- )
+ return vim.lsp.start({
+ name = 'dummy',
+ cmd = server.cmd,
+ on_attach = function(client, bufnr0)
+ vim.lsp.completion.enable(true, client.id, bufnr0, {
+ convert = function(item)
+ return { abbr = item.label:gsub('%b()', '') }
+ end,
+ })
+ end,
+ })
+ end)
end
local function assert_matches(fn)
@@ -533,14 +528,11 @@ describe('vim.lsp.completion: protocol', function()
--- @param pos [integer, integer]
local function trigger_at_pos(pos)
- exec_lua(
- [[
+ exec_lua(function()
local win = vim.api.nvim_get_current_win()
- vim.api.nvim_win_set_cursor(win, ...)
+ vim.api.nvim_win_set_cursor(win, pos)
vim.lsp.completion.trigger()
- ]],
- pos
- )
+ end)
retry(nil, nil, function()
neq(nil, exec_lua('return _G.capture.col'))
@@ -683,37 +675,30 @@ describe('vim.lsp.completion: protocol', function()
}
local client_id = create_server(completion_list)
- exec_lua(
- [[
+ exec_lua(function()
_G.called = false
- local client = vim.lsp.get_client_by_id(...)
- client.commands.dummy = function ()
+ local client = assert(vim.lsp.get_client_by_id(client_id))
+ client.commands.dummy = function()
_G.called = true
end
- ]],
- client_id
- )
+ end)
feed('ih')
trigger_at_pos({ 1, 1 })
- exec_lua(
- [[
- local client_id, item = ...
+ local item = completion_list.items[1]
+ exec_lua(function()
vim.v.completed_item = {
user_data = {
nvim = {
lsp = {
client_id = client_id,
- completion_item = item
- }
- }
- }
+ completion_item = item,
+ },
+ },
+ },
}
- ]],
- client_id,
- completion_list.items[1]
- )
+ end)
feed('<C-x><C-o><C-y>')