mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
test: support upvalues in exec_lua
This commit is contained in:
committed by
Lewis Russell
parent
a19e89022d
commit
e5c174421d
@@ -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>')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user