diff options
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 159 |
1 files changed, 80 insertions, 79 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 86b9be79e0..252931eccb 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -11,19 +11,20 @@ local eq = helpers.eq local eval = helpers.eval local matches = helpers.matches local pcall_err = helpers.pcall_err -local pesc = helpers.pesc +local pesc = vim.pesc local insert = helpers.insert -local funcs = helpers.funcs +local fn = helpers.fn local retry = helpers.retry local stop = helpers.stop -local NIL = helpers.NIL +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 meths = helpers.meths +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 @@ -362,9 +363,9 @@ describe('LSP', function() end, on_handler = function(_, _, ctx) if ctx.method == 'finish' then - eq('basic_init', meths.get_var('lsp_attached')) + eq('basic_init', api.nvim_get_var('lsp_attached')) exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') - eq('basic_init', meths.get_var('lsp_detached')) + eq('basic_init', api.nvim_get_var('lsp_detached')) client.stop() end end, @@ -728,8 +729,8 @@ describe('LSP', function() on_handler = function(err, result, ctx) eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'start' then - local tmpfile_old = helpers.tmpname() - local tmpfile_new = helpers.tmpname() + local tmpfile_old = tmpname() + local tmpfile_new = tmpname() os.remove(tmpfile_new) exec_lua( [=[ @@ -1876,7 +1877,7 @@ describe('LSP', function() describe('cursor position', function() it("don't fix the cursor if the range contains the cursor", function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 19, 'Second line of text'), } @@ -1888,11 +1889,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 6 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 6 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid col if the content was removed', function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(1, 6, 1, 19, ''), @@ -1905,11 +1906,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid row if the content was removed', function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(0, 18, 5, 0, ''), @@ -1918,11 +1919,11 @@ describe('LSP', function() eq({ 'First line of text', }, buf_lines(1)) - eq({ 1, 17 }, funcs.nvim_win_get_cursor(0)) + eq({ 1, 17 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor row', function() - funcs.nvim_win_set_cursor(0, { 3, 0 }) + fn.nvim_win_set_cursor(0, { 3, 0 }) local edits = { make_edit(1, 0, 2, 0, ''), } @@ -1933,14 +1934,14 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 0 }, fn.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, { '' }) - funcs.nvim_win_set_cursor(0, { 2, 11 }) + fn.nvim_win_set_cursor(0, { 2, 11 }) local edits = { make_edit(1, 7, 1, 11, ''), } @@ -1953,11 +1954,11 @@ describe('LSP', function() 'å å ɧ 汉语 ↥ 🤦 🦄', '', }, buf_lines(1)) - eq({ 2, 7 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 7 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor row and col', function() - funcs.nvim_win_set_cursor(0, { 2, 12 }) + fn.nvim_win_set_cursor(0, { 2, 12 }) local edits = { make_edit(0, 11, 1, 12, ''), } @@ -1968,7 +1969,7 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 1, 11 }, funcs.nvim_win_get_cursor(0)) + eq({ 1, 11 }, fn.nvim_win_get_cursor(0)) end) end) @@ -2278,7 +2279,7 @@ describe('LSP', function() ) end) it('Supports file creation with CreateFile payload', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) -- Should not exist, only interested in a tmpname local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2295,7 +2296,7 @@ describe('LSP', function() it( 'Supports file creation in folder that needs to be created with CreateFile payload', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) -- Should not exist, only interested in a tmpname tmpfile = tmpfile .. '/dummy/x/' local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) @@ -2312,7 +2313,7 @@ describe('LSP', function() end ) it('createFile does not touch file if it exists and ignoreIfExists is set', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Dummy content') local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2331,7 +2332,7 @@ describe('LSP', function() eq('Dummy content', read_file(tmpfile)) end) it('createFile overrides file if overwrite is set', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Dummy content') local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2351,7 +2352,7 @@ describe('LSP', function() eq('', read_file(tmpfile)) end) it('DeleteFile delete file and buffer', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Be gone') local uri = exec_lua( [[ @@ -2375,7 +2376,7 @@ describe('LSP', function() eq(false, exec_lua('return vim.api.nvim_buf_is_loaded(vim.fn.bufadd(...))', tmpfile)) end) it('DeleteFile fails if file does not exist and ignoreIfNotExists is false', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2398,9 +2399,9 @@ describe('LSP', function() local pathsep = helpers.get_pathsep() it('Can rename an existing file', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Test content') - local new = helpers.tmpname() + local new = tmpname() os.remove(new) -- only reserve the name, file must not exist for the test scenario local lines = exec_lua( [[ @@ -2424,9 +2425,9 @@ describe('LSP', function() os.remove(new) end) it('Kills old buffer after renaming an existing file', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Test content') - local new = helpers.tmpname() + local new = tmpname() os.remove(new) -- only reserve the name, file must not exist for the test scenario local lines = exec_lua( [[ @@ -2444,8 +2445,8 @@ describe('LSP', function() end) it('Can rename a directory', function() -- only reserve the name, file must not exist for the test scenario - local old_dir = helpers.tmpname() - local new_dir = helpers.tmpname() + local old_dir = tmpname() + local new_dir = tmpname() os.remove(old_dir) os.remove(new_dir) @@ -2479,9 +2480,9 @@ describe('LSP', function() it( 'Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Old File') - local new = helpers.tmpname() + local new = tmpname() write_file(new, 'New file') exec_lua( @@ -2514,9 +2515,9 @@ describe('LSP', function() end ) it('Does override target if overwrite is true', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Old file') - local new = helpers.tmpname() + local new = tmpname() write_file(new, 'New file') exec_lua( [[ @@ -2945,14 +2946,14 @@ describe('LSP', function() end) it('adds current position to jumplist before jumping', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + fn.nvim_win_set_buf(0, target_bufnr) + local mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_cursor(0, { 2, 3 }) jump(location(0, 9, 0, 9)) - mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 2, 3 }, mark) end) end) @@ -3046,101 +3047,101 @@ describe('LSP', function() end) it('does not add current position to jumplist if not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + fn.nvim_win_set_buf(0, target_bufnr) + local mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.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 = funcs.nvim_buf_get_mark(target_bufnr, "'") + mark = fn.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() - funcs.nvim_win_set_buf(0, target_bufnr) - local cursor = funcs.nvim_win_get_cursor(0) + fn.nvim_win_set_buf(0, target_bufnr) + local cursor = fn.nvim_win_get_cursor(0) show_document(location(0, 9, 0, 9), false, false) - eq(cursor, funcs.nvim_win_get_cursor(0)) + eq(cursor, fn.nvim_win_get_cursor(0)) end) it('does not change window if not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local win = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr) + local win = fn.nvim_get_current_win() -- same document/bufnr show_document(location(0, 9, 0, 9), false, true) - eq(win, funcs.nvim_get_current_win()) + eq(win, fn.nvim_get_current_win()) -- different document/bufnr, new window/split show_document(location(0, 9, 0, 9, true), false, true) - eq(2, #funcs.nvim_list_wins()) - eq(win, funcs.nvim_get_current_win()) + eq(2, #fn.nvim_list_wins()) + eq(win, fn.nvim_get_current_win()) end) it("respects 'reuse_win' parameter", function() - funcs.nvim_win_set_buf(0, target_bufnr) + fn.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, #funcs.nvim_list_wins()) + eq(1, #fn.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, #funcs.nvim_list_wins()) + eq(2, #fn.nvim_list_wins()) end) it('correctly sets the cursor of the split if range is given without focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_buf(0, target_bufnr) show_document(location(0, 9, 0, 9, true), false, true) - local wins = funcs.nvim_list_wins() + local wins = fn.nvim_list_wins() eq(2, #wins) table.sort(wins) - eq({ 1, 0 }, funcs.nvim_win_get_cursor(wins[1])) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(wins[2])) + eq({ 1, 0 }, fn.nvim_win_get_cursor(wins[1])) + eq({ 1, 9 }, fn.nvim_win_get_cursor(wins[2])) end) it('does not change cursor of the split if not range and not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_cursor(0, { 2, 3 }) exec_lua([[vim.cmd.new()]]) - funcs.nvim_win_set_buf(0, target_bufnr2) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_buf(0, target_bufnr2) + fn.nvim_win_set_cursor(0, { 2, 3 }) show_document({ uri = 'file:///fake/uri2' }, false, true) - local wins = funcs.nvim_list_wins() + local wins = fn.nvim_list_wins() eq(2, #wins) - eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[1])) - eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[2])) + eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[1])) + eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[2])) end) it('respects existing buffers', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local win = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr) + local win = fn.nvim_get_current_win() exec_lua([[vim.cmd.new()]]) - funcs.nvim_win_set_buf(0, target_bufnr2) - funcs.nvim_win_set_cursor(0, { 2, 3 }) - local split = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr2) + fn.nvim_win_set_cursor(0, { 2, 3 }) + local split = fn.nvim_get_current_win() -- reuse win for open document/bufnr if called from split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) - eq(2, #funcs.nvim_list_wins()) + eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) + eq(2, #fn.nvim_list_wins()) - funcs.nvim_set_current_win(win) + fn.nvim_set_current_win(win) -- reuse win for open document/bufnr if called outside the split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) - eq(2, #funcs.nvim_list_wins()) + eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) + eq(2, #fn.nvim_list_wins()) end) end) @@ -4043,7 +4044,7 @@ describe('LSP', function() if is_os('win') then tmpfile = '\\\\.\\\\pipe\\pipe.test' else - tmpfile = helpers.tmpname() + tmpfile = tmpname() os.remove(tmpfile) end local result = exec_lua( @@ -4150,7 +4151,7 @@ describe('LSP', function() describe('#dynamic vim.lsp._dynamic', function() it('supports dynamic registration', function() ---@type string - local root_dir = helpers.tmpname() + local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) local tmpfile = root_dir .. '/dynamic.foo' @@ -4261,7 +4262,7 @@ describe('LSP', function() describe('vim.lsp._watchfiles', function() it('sends notifications when files change', function() skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change') - local root_dir = helpers.tmpname() + local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) |