aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
commitff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch)
tree729bbcb92231538fa61dab6c3d890b025484b7f5 /test/functional/plugin/lsp_spec.lua
parent376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff)
parent28c04948a1c887a1cc0cb64de79fa32631700466 (diff)
downloadrneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r--test/functional/plugin/lsp_spec.lua1011
1 files changed, 780 insertions, 231 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 4826153edb..c95a96baca 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -1,36 +1,38 @@
-local helpers = require('test.functional.helpers')(after_each)
-local lsp_helpers = require('test.functional.plugin.lsp.helpers')
-
-local assert_log = helpers.assert_log
-local buf_lines = helpers.buf_lines
-local clear = helpers.clear
-local command = helpers.command
-local dedent = helpers.dedent
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local eval = helpers.eval
-local matches = helpers.matches
-local pcall_err = helpers.pcall_err
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local t_lsp = require('test.functional.plugin.lsp.testutil')
+
+local assert_log = t.assert_log
+local buf_lines = n.buf_lines
+local clear = n.clear
+local command = n.command
+local dedent = t.dedent
+local exec_lua = n.exec_lua
+local eq = t.eq
+local eval = n.eval
+local matches = t.matches
+local pcall_err = t.pcall_err
local pesc = vim.pesc
-local insert = helpers.insert
-local fn = helpers.fn
-local retry = helpers.retry
-local stop = helpers.stop
+local insert = n.insert
+local fn = n.fn
+local retry = t.retry
+local stop = n.stop
local NIL = vim.NIL
-local read_file = require('test.helpers').read_file
-local write_file = require('test.helpers').write_file
-local is_ci = helpers.is_ci
-local api = helpers.api
-local is_os = helpers.is_os
-local skip = helpers.skip
-local mkdir = helpers.mkdir
-local tmpname = helpers.tmpname
-
-local clear_notrace = lsp_helpers.clear_notrace
-local create_server_definition = lsp_helpers.create_server_definition
-local fake_lsp_code = lsp_helpers.fake_lsp_code
-local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile
-local test_rpc_server = lsp_helpers.test_rpc_server
+local read_file = t.read_file
+local write_file = t.write_file
+local is_ci = t.is_ci
+local api = n.api
+local is_os = t.is_os
+local skip = t.skip
+local mkdir = t.mkdir
+local tmpname = t.tmpname
+
+local clear_notrace = t_lsp.clear_notrace
+local create_server_definition = t_lsp.create_server_definition
+local fake_lsp_code = t_lsp.fake_lsp_code
+local fake_lsp_logfile = t_lsp.fake_lsp_logfile
+local test_rpc_server = t_lsp.test_rpc_server
local function get_buf_option(name, bufnr)
bufnr = bufnr or 'BUFFER'
@@ -83,7 +85,7 @@ describe('LSP', function()
end)
after_each(function()
- exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
-- exec_lua("lsp.stop_all_clients(true)")
end)
@@ -146,7 +148,7 @@ describe('LSP', function()
after_each(function()
stop()
exec_lua('lsp.stop_client(lsp.get_clients(), true)')
- exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })")
+ api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
end)
it('should run correctly', function()
@@ -249,7 +251,7 @@ describe('LSP', function()
if is_ci() then
pending('hangs the build on CI #14028, re-enable with freeze timeout #14204')
return
- elseif helpers.skip_fragile(pending) then
+ elseif t.skip_fragile(pending) then
return
end
local expected_handlers = {
@@ -279,7 +281,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
{ NIL, {}, { method = 'finish', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_finish',
on_setup = function()
@@ -312,7 +314,7 @@ describe('LSP', function()
end)
it('should fire autocommands on attach and detach', function()
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_init',
on_setup = function()
@@ -349,7 +351,7 @@ describe('LSP', function()
end)
it('should set default options on attach', function()
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'set_defaults_all_capabilities',
on_init = function(_client)
@@ -397,7 +399,7 @@ describe('LSP', function()
end)
it('should overwrite options set by ftplugins', function()
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'set_defaults_all_capabilities',
on_init = function(_client)
@@ -437,7 +439,7 @@ describe('LSP', function()
end)
it('should not overwrite user-defined options', function()
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'set_defaults_all_capabilities',
on_init = function(_client)
@@ -473,6 +475,12 @@ describe('LSP', function()
local server = _create_server()
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_current_buf(bufnr)
+ local detach_called = false
+ vim.api.nvim_create_autocmd("LspDetach", {
+ callback = function()
+ detach_called = true
+ end
+ })
local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server.cmd })
assert(client_id, "lsp.start must return client_id")
local client = vim.lsp.get_client_by_id(client_id)
@@ -484,11 +492,42 @@ describe('LSP', function()
client_id = client_id,
num_attached_before = num_attached_before,
num_attached_after = num_attached_after,
+ detach_called = detach_called,
}
]])
eq(true, result ~= nil, 'exec_lua must return result')
eq(1, result.num_attached_before)
eq(0, result.num_attached_after)
+ eq(true, result.detach_called)
+ end)
+
+ it('should not re-attach buffer if it was deleted in on_init #28575', function()
+ clear()
+ exec_lua(create_server_definition)
+ exec_lua([[
+ local server = _create_server({
+ handlers = {
+ initialize = function(method, params, callback)
+ vim.schedule(function()
+ callback(nil, { capabilities = {} })
+ end)
+ end
+ }
+ })
+ local bufnr = vim.api.nvim_create_buf(false, true)
+ local on_init_called = false
+ local client_id = vim.lsp.start({
+ name = 'detach-dummy',
+ cmd = server.cmd,
+ on_init = function()
+ vim.api.nvim_buf_delete(bufnr, {})
+ on_init_called = true
+ end
+ })
+ vim.lsp.buf_attach_client(bufnr, client_id)
+ local ok = vim.wait(1000, function() return on_init_called end)
+ assert(ok, "on_init was not called")
+ ]])
end)
it('client should return settings via workspace/configuration handler', function()
@@ -508,7 +547,7 @@ describe('LSP', function()
},
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_workspace_configuration',
on_init = function(_client)
@@ -598,7 +637,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'text_document_sync_save_bool',
on_init = function(c)
@@ -641,11 +680,11 @@ describe('LSP', function()
vim.lsp.stop_client(client_id)
return server.messages
]])
- eq(#messages, 4)
- eq(messages[1].method, 'initialize')
- eq(messages[2].method, 'initialized')
- eq(messages[3].method, 'shutdown')
- eq(messages[4].method, 'exit')
+ eq(4, #messages)
+ eq('initialize', messages[1].method)
+ eq('initialized', messages[2].method)
+ eq('shutdown', messages[3].method)
+ eq('exit', messages[4].method)
end)
it('BufWritePre sends willSave / willSaveWaitUntil, applies textEdits', function()
@@ -660,7 +699,7 @@ describe('LSP', function()
}
},
handlers = {
- ['textDocument/willSaveWaitUntil'] = function()
+ ['textDocument/willSaveWaitUntil'] = function(_, _, callback)
local text_edit = {
range = {
start = { line = 0, character = 0 },
@@ -668,7 +707,7 @@ describe('LSP', function()
},
newText = 'Hello'
}
- return { text_edit, }
+ callback(nil, { text_edit, })
end
},
})
@@ -692,7 +731,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server({
test_name = 'text_document_save_did_open',
on_init = function(c)
@@ -732,7 +771,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'text_document_sync_save_includeText',
on_init = function(c)
@@ -808,14 +847,12 @@ describe('LSP', function()
BUFFER = vim.api.nvim_get_current_buf()
lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)
vim.lsp.handlers['textDocument/typeDefinition'] = function() end
+ vim.cmd(BUFFER.."bwipeout")
]=])
end,
on_init = function(client)
client.stop()
exec_lua('vim.lsp.buf.type_definition()')
- exec_lua [[
- vim.api.nvim_command(BUFFER.."bwipeout")
- ]]
end,
on_exit = function(code, signal)
eq(0, code, 'exit code')
@@ -859,7 +896,7 @@ describe('LSP', function()
local expected_handlers = {
{ NIL, {}, { method = 'finish', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_forward_request_cancelled',
on_init = function(_client)
@@ -885,7 +922,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ { code = -32801 }, NIL, { method = 'error_code_test', bufnr = 1, client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_forward_content_modified',
on_init = function(_client)
@@ -915,7 +952,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_pending_request_tracked',
on_init = function(_client)
@@ -949,7 +986,7 @@ describe('LSP', function()
local expected_handlers = {
{ NIL, {}, { method = 'finish', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_cancel_request_tracked',
on_init = function(_client)
@@ -982,7 +1019,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_tracked_requests_cleared',
on_init = function(_client)
@@ -1021,7 +1058,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'check_tracked_requests_cleared',
on_init = function(_client)
@@ -1057,7 +1094,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
{ NIL, {}, { method = 'finish', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_finish',
on_setup = function()
@@ -1067,12 +1104,10 @@ describe('LSP', function()
"testing";
"123";
})
- ]]
- eq(1, exec_lua('return TEST_RPC_CLIENT_ID'))
- eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)'))
- eq(true, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)'))
- exec_lua [[
- vim.api.nvim_command(BUFFER.."bwipeout")
+ assert(TEST_RPC_CLIENT_ID == 1)
+ assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID))
+ assert(lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID))
+ vim.cmd(BUFFER.."bwipeout")
]]
end,
on_init = function(_client)
@@ -1101,7 +1136,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open',
on_setup = function()
@@ -1147,7 +1182,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open',
on_setup = function()
@@ -1190,7 +1225,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change',
on_setup = function()
@@ -1238,7 +1273,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change_noeol',
on_setup = function()
@@ -1305,7 +1340,7 @@ describe('LSP', function()
},
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'inlay_hint',
on_setup = function()
@@ -1332,7 +1367,7 @@ describe('LSP', function()
on_handler = function(err, result, ctx)
if ctx.method == 'start' then
exec_lua [[
- vim.lsp.inlay_hint.enable(BUFFER)
+ vim.lsp.inlay_hint.enable(true, { bufnr = BUFFER })
]]
end
if ctx.method == 'textDocument/inlayHint' then
@@ -1352,7 +1387,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change_incremental',
options = {
@@ -1403,7 +1438,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change_incremental',
options = {
@@ -1457,7 +1492,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change_incremental_editing',
on_setup = function()
@@ -1485,7 +1520,7 @@ describe('LSP', function()
end,
on_handler = function(err, result, ctx)
if ctx.method == 'start' then
- helpers.command('normal! 1Go')
+ n.command('normal! 1Go')
client.notify('finish')
end
eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler')
@@ -1502,7 +1537,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change_multi',
on_setup = function()
@@ -1553,7 +1588,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'basic_check_buffer_open_and_change_multi_and_close',
on_setup = function()
@@ -1607,7 +1642,7 @@ describe('LSP', function()
{ NIL, {}, { method = 'finish', client_id = 1 } },
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'invalid_header',
on_setup = function() end,
@@ -1640,7 +1675,7 @@ describe('LSP', function()
},
{ NIL, {}, { method = 'start', client_id = 1 } },
}
- local client
+ local client --- @type vim.lsp.Client
test_rpc_server {
test_name = 'decode_nil',
on_setup = function()
@@ -1807,7 +1842,7 @@ describe('LSP', function()
make_edit(1, 0, 2, 5, 'foobar'),
make_edit(4, 0, 5, 0, 'barfoo'),
}
- eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 1, {})'))
+ eq(true, api.nvim_buf_set_mark(1, 'a', 2, 1, {}))
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16')
eq({
'First line of text',
@@ -1815,7 +1850,7 @@ describe('LSP', function()
'Fourth line of text',
'barfoo',
}, buf_lines(1))
- local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")')
+ local mark = api.nvim_buf_get_mark(1, 'a')
eq({ 2, 1 }, mark)
end)
@@ -1824,7 +1859,7 @@ describe('LSP', function()
make_edit(1, 0, 2, 15, 'foobar'),
make_edit(4, 0, 5, 0, 'barfoo'),
}
- eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 10, {})'))
+ eq(true, api.nvim_buf_set_mark(1, 'a', 2, 10, {}))
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16')
eq({
'First line of text',
@@ -1832,7 +1867,7 @@ describe('LSP', function()
'Fourth line of text',
'barfoo',
}, buf_lines(1))
- local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")')
+ local mark = api.nvim_buf_get_mark(1, 'a')
eq({ 2, 9 }, mark)
end)
@@ -1841,19 +1876,19 @@ describe('LSP', function()
make_edit(1, 0, 4, 5, 'foobar'),
make_edit(4, 0, 5, 0, 'barfoo'),
}
- eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 4, 1, {})'))
+ eq(true, api.nvim_buf_set_mark(1, 'a', 4, 1, {}))
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16')
eq({
'First line of text',
'foobaro',
}, buf_lines(1))
- local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")')
+ local mark = api.nvim_buf_get_mark(1, 'a')
eq({ 2, 1 }, mark)
end)
describe('cursor position', function()
it("don't fix the cursor if the range contains the cursor", function()
- fn.nvim_win_set_cursor(0, { 2, 6 })
+ api.nvim_win_set_cursor(0, { 2, 6 })
local edits = {
make_edit(1, 0, 1, 19, 'Second line of text'),
}
@@ -1865,11 +1900,11 @@ describe('LSP', function()
'Fourth line of text',
'å å ɧ 汉语 ↥ 🤦 🦄',
}, buf_lines(1))
- eq({ 2, 6 }, fn.nvim_win_get_cursor(0))
+ eq({ 2, 6 }, api.nvim_win_get_cursor(0))
end)
it('fix the cursor to the valid col if the content was removed', function()
- fn.nvim_win_set_cursor(0, { 2, 6 })
+ api.nvim_win_set_cursor(0, { 2, 6 })
local edits = {
make_edit(1, 0, 1, 6, ''),
make_edit(1, 6, 1, 19, ''),
@@ -1882,11 +1917,11 @@ describe('LSP', function()
'Fourth line of text',
'å å ɧ 汉语 ↥ 🤦 🦄',
}, buf_lines(1))
- eq({ 2, 0 }, fn.nvim_win_get_cursor(0))
+ eq({ 2, 0 }, api.nvim_win_get_cursor(0))
end)
it('fix the cursor to the valid row if the content was removed', function()
- fn.nvim_win_set_cursor(0, { 2, 6 })
+ api.nvim_win_set_cursor(0, { 2, 6 })
local edits = {
make_edit(1, 0, 1, 6, ''),
make_edit(0, 18, 5, 0, ''),
@@ -1895,11 +1930,11 @@ describe('LSP', function()
eq({
'First line of text',
}, buf_lines(1))
- eq({ 1, 17 }, fn.nvim_win_get_cursor(0))
+ eq({ 1, 17 }, api.nvim_win_get_cursor(0))
end)
it('fix the cursor row', function()
- fn.nvim_win_set_cursor(0, { 3, 0 })
+ api.nvim_win_set_cursor(0, { 3, 0 })
local edits = {
make_edit(1, 0, 2, 0, ''),
}
@@ -1910,14 +1945,14 @@ describe('LSP', function()
'Fourth line of text',
'å å ɧ 汉语 ↥ 🤦 🦄',
}, buf_lines(1))
- eq({ 2, 0 }, fn.nvim_win_get_cursor(0))
+ eq({ 2, 0 }, api.nvim_win_get_cursor(0))
end)
it('fix the cursor col', function()
-- append empty last line. See #22636
- exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, { '' })
+ api.nvim_buf_set_lines(1, -1, -1, true, { '' })
- fn.nvim_win_set_cursor(0, { 2, 11 })
+ api.nvim_win_set_cursor(0, { 2, 11 })
local edits = {
make_edit(1, 7, 1, 11, ''),
}
@@ -1930,11 +1965,11 @@ describe('LSP', function()
'å å ɧ 汉语 ↥ 🤦 🦄',
'',
}, buf_lines(1))
- eq({ 2, 7 }, fn.nvim_win_get_cursor(0))
+ eq({ 2, 7 }, api.nvim_win_get_cursor(0))
end)
it('fix the cursor row and col', function()
- fn.nvim_win_set_cursor(0, { 2, 12 })
+ api.nvim_win_set_cursor(0, { 2, 12 })
local edits = {
make_edit(0, 11, 1, 12, ''),
}
@@ -1945,7 +1980,7 @@ describe('LSP', function()
'Fourth line of text',
'å å ɧ 汉语 ↥ 🤦 🦄',
}, buf_lines(1))
- eq({ 1, 11 }, fn.nvim_win_get_cursor(0))
+ eq({ 1, 11 }, api.nvim_win_get_cursor(0))
end)
end)
@@ -2021,7 +2056,7 @@ describe('LSP', function()
end)
describe('apply_text_document_edit', function()
- local target_bufnr
+ local target_bufnr --- @type integer
local text_document_edit = function(editVersion)
return {
edits = {
@@ -2267,7 +2302,7 @@ describe('LSP', function()
},
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
+ eq(true, vim.uv.fs_stat(tmpfile) ~= nil)
end)
it(
'Supports file creation in folder that needs to be created with CreateFile payload',
@@ -2285,7 +2320,7 @@ describe('LSP', function()
},
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
+ eq(true, vim.uv.fs_stat(tmpfile) ~= nil)
end
)
it('createFile does not touch file if it exists and ignoreIfExists is set', function()
@@ -2304,7 +2339,7 @@ describe('LSP', function()
},
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
+ eq(true, vim.uv.fs_stat(tmpfile) ~= nil)
eq('Dummy content', read_file(tmpfile))
end)
it('createFile overrides file if overwrite is set', function()
@@ -2324,7 +2359,7 @@ describe('LSP', function()
},
}
exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
+ eq(true, vim.uv.fs_stat(tmpfile) ~= nil)
eq('', read_file(tmpfile))
end)
it('DeleteFile delete file and buffer', function()
@@ -2348,8 +2383,8 @@ describe('LSP', function()
},
}
eq(true, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16'))
- eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
- eq(false, exec_lua('return vim.api.nvim_buf_is_loaded(vim.fn.bufadd(...))', tmpfile))
+ eq(false, vim.uv.fs_stat(tmpfile) ~= nil)
+ eq(false, api.nvim_buf_is_loaded(fn.bufadd(tmpfile)))
end)
it('DeleteFile fails if file does not exist and ignoreIfNotExists is false', function()
local tmpfile = tmpname()
@@ -2367,12 +2402,12 @@ describe('LSP', function()
},
}
eq(false, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit))
- eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile))
+ eq(false, vim.uv.fs_stat(tmpfile) ~= nil)
end)
end)
describe('lsp.util.rename', function()
- local pathsep = helpers.get_pathsep()
+ local pathsep = n.get_pathsep()
it('Can rename an existing file', function()
local old = tmpname()
@@ -2395,9 +2430,9 @@ describe('LSP', function()
new
)
eq({ 'Test content' }, lines)
- local exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', old)
+ local exists = vim.uv.fs_stat(old) ~= nil
eq(false, exists)
- exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', new)
+ exists = vim.uv.fs_stat(new) ~= nil
eq(true, exists)
os.remove(new)
end)
@@ -2408,7 +2443,7 @@ describe('LSP', function()
os.remove(old_dir)
os.remove(new_dir)
- helpers.mkdir_p(old_dir)
+ n.mkdir_p(old_dir)
local file = 'file.txt'
write_file(old_dir .. pathsep .. file, 'Test content')
@@ -2433,9 +2468,9 @@ describe('LSP', function()
file
)
eq({ 'Test content' }, lines)
- eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old_dir))
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir))
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir .. pathsep .. file))
+ eq(false, vim.uv.fs_stat(old_dir) ~= nil)
+ eq(true, vim.uv.fs_stat(new_dir) ~= nil)
+ eq(true, vim.uv.fs_stat(new_dir .. pathsep .. file) ~= nil)
os.remove(new_dir)
end)
@@ -2444,7 +2479,7 @@ describe('LSP', function()
local new = tmpname()
os.remove(old)
os.remove(new)
- helpers.mkdir_p(old)
+ n.mkdir_p(old)
local result = exec_lua(
[[
@@ -2499,7 +2534,7 @@ describe('LSP', function()
new
)
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, vim.uv.fs_stat(old) ~= nil)
eq('New file', read_file(new))
exec_lua(
@@ -2513,7 +2548,7 @@ describe('LSP', function()
new
)
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
+ eq(true, vim.uv.fs_stat(old) ~= nil)
eq('New file', read_file(new))
end
)
@@ -2543,8 +2578,8 @@ describe('LSP', function()
old,
new
)
- eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(false, vim.uv.fs_stat(old) ~= nil)
+ eq(true, vim.uv.fs_stat(new) ~= nil)
eq(true, undo_kept)
end)
it('Maintains undo information for unloaded buffer', function()
@@ -2570,8 +2605,8 @@ describe('LSP', function()
old,
new
)
- eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(false, vim.uv.fs_stat(old) ~= nil)
+ eq(true, vim.uv.fs_stat(new) ~= nil)
eq(true, undo_kept)
end)
it('Does not rename file when it conflicts with a buffer without file', function()
@@ -2615,8 +2650,8 @@ describe('LSP', function()
new
)
- eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old))
- eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new))
+ eq(false, vim.uv.fs_stat(old) ~= nil)
+ eq(true, vim.uv.fs_stat(new) ~= nil)
eq('Old file', read_file(new))
end)
end)
@@ -2697,6 +2732,7 @@ describe('LSP', function()
eq(expected, actual)
end)
end)
+
describe('lsp.util.symbols_to_items', function()
describe('convert DocumentSymbol[] to items', function()
it('DocumentSymbol has children', function()
@@ -2971,7 +3007,7 @@ describe('LSP', function()
end)
describe('lsp.util.jump_to_location', function()
- local target_bufnr
+ local target_bufnr --- @type integer
before_each(function()
target_bufnr = exec_lua [[
@@ -2994,10 +3030,10 @@ describe('LSP', function()
local jump = function(msg)
eq(true, exec_lua('return vim.lsp.util.jump_to_location(...)', msg, 'utf-16'))
- eq(target_bufnr, exec_lua [[return vim.fn.bufnr('%')]])
+ eq(target_bufnr, fn.bufnr('%'))
return {
- line = exec_lua [[return vim.fn.line('.')]],
- col = exec_lua [[return vim.fn.col('.')]],
+ line = fn.line('.'),
+ col = fn.col('.'),
}
end
@@ -3027,25 +3063,25 @@ describe('LSP', function()
local pos = jump(location(1, 2, 1, 2))
eq(2, pos.line)
eq(4, pos.col)
- eq('å', exec_lua [[return vim.fn.expand('<cword>')]])
+ eq('å', fn.expand('<cword>'))
end)
it('adds current position to jumplist before jumping', function()
- fn.nvim_win_set_buf(0, target_bufnr)
- local mark = fn.nvim_buf_get_mark(target_bufnr, "'")
+ api.nvim_win_set_buf(0, target_bufnr)
+ local mark = api.nvim_buf_get_mark(target_bufnr, "'")
eq({ 1, 0 }, mark)
- fn.nvim_win_set_cursor(0, { 2, 3 })
+ api.nvim_win_set_cursor(0, { 2, 3 })
jump(location(0, 9, 0, 9))
- mark = fn.nvim_buf_get_mark(target_bufnr, "'")
+ mark = api.nvim_buf_get_mark(target_bufnr, "'")
eq({ 2, 3 }, mark)
end)
end)
describe('lsp.util.show_document', function()
- local target_bufnr
- local target_bufnr2
+ local target_bufnr --- @type integer
+ local target_bufnr2 --- @type integer
before_each(function()
target_bufnr = exec_lua([[
@@ -3084,11 +3120,11 @@ describe('LSP', function()
)
)
if focus == true or focus == nil then
- eq(target_bufnr, exec_lua([[return vim.fn.bufnr('%')]]))
+ eq(target_bufnr, fn.bufnr('%'))
end
return {
- line = exec_lua([[return vim.fn.line('.')]]),
- col = exec_lua([[return vim.fn.col('.')]]),
+ line = fn.line('.'),
+ col = fn.col('.'),
}
end
@@ -3132,101 +3168,101 @@ describe('LSP', function()
end)
it('does not add current position to jumplist if not focus', function()
- fn.nvim_win_set_buf(0, target_bufnr)
- local mark = fn.nvim_buf_get_mark(target_bufnr, "'")
+ api.nvim_win_set_buf(0, target_bufnr)
+ local mark = api.nvim_buf_get_mark(target_bufnr, "'")
eq({ 1, 0 }, mark)
- fn.nvim_win_set_cursor(0, { 2, 3 })
+ api.nvim_win_set_cursor(0, { 2, 3 })
show_document(location(0, 9, 0, 9), false, true)
show_document(location(0, 9, 0, 9, true), false, true)
- mark = fn.nvim_buf_get_mark(target_bufnr, "'")
+ mark = api.nvim_buf_get_mark(target_bufnr, "'")
eq({ 1, 0 }, mark)
end)
it('does not change cursor position if not focus and not reuse_win', function()
- fn.nvim_win_set_buf(0, target_bufnr)
- local cursor = fn.nvim_win_get_cursor(0)
+ api.nvim_win_set_buf(0, target_bufnr)
+ local cursor = api.nvim_win_get_cursor(0)
show_document(location(0, 9, 0, 9), false, false)
- eq(cursor, fn.nvim_win_get_cursor(0))
+ eq(cursor, api.nvim_win_get_cursor(0))
end)
it('does not change window if not focus', function()
- fn.nvim_win_set_buf(0, target_bufnr)
- local win = fn.nvim_get_current_win()
+ api.nvim_win_set_buf(0, target_bufnr)
+ local win = api.nvim_get_current_win()
-- same document/bufnr
show_document(location(0, 9, 0, 9), false, true)
- eq(win, fn.nvim_get_current_win())
+ eq(win, api.nvim_get_current_win())
-- different document/bufnr, new window/split
show_document(location(0, 9, 0, 9, true), false, true)
- eq(2, #fn.nvim_list_wins())
- eq(win, fn.nvim_get_current_win())
+ eq(2, #api.nvim_list_wins())
+ eq(win, api.nvim_get_current_win())
end)
it("respects 'reuse_win' parameter", function()
- fn.nvim_win_set_buf(0, target_bufnr)
+ api.nvim_win_set_buf(0, target_bufnr)
-- does not create a new window if the buffer is already open
show_document(location(0, 9, 0, 9), false, true)
- eq(1, #fn.nvim_list_wins())
+ eq(1, #api.nvim_list_wins())
-- creates a new window even if the buffer is already open
show_document(location(0, 9, 0, 9), false, false)
- eq(2, #fn.nvim_list_wins())
+ eq(2, #api.nvim_list_wins())
end)
it('correctly sets the cursor of the split if range is given without focus', function()
- fn.nvim_win_set_buf(0, target_bufnr)
+ api.nvim_win_set_buf(0, target_bufnr)
show_document(location(0, 9, 0, 9, true), false, true)
- local wins = fn.nvim_list_wins()
+ local wins = api.nvim_list_wins()
eq(2, #wins)
table.sort(wins)
- eq({ 1, 0 }, fn.nvim_win_get_cursor(wins[1]))
- eq({ 1, 9 }, fn.nvim_win_get_cursor(wins[2]))
+ eq({ 1, 0 }, api.nvim_win_get_cursor(wins[1]))
+ eq({ 1, 9 }, api.nvim_win_get_cursor(wins[2]))
end)
it('does not change cursor of the split if not range and not focus', function()
- fn.nvim_win_set_buf(0, target_bufnr)
- fn.nvim_win_set_cursor(0, { 2, 3 })
+ api.nvim_win_set_buf(0, target_bufnr)