diff options
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/api/server_notifications_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/fixtures/fake-lsp-server.lua | 83 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 72 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 86 |
4 files changed, 208 insertions, 41 deletions
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 279ede81f7..6367cc5caa 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -78,10 +78,10 @@ describe('notify', function() end) it('cancels stale events on channel close', function() - if isCI() then - pending('Sporadic hangs on CI (c.f., #14083). Skip until it is fixed.') - return - end + if isCI() then + pending('hangs on CI #14083 #15251') + return + end if helpers.pending_win32(pending) then return end local catchan = eval("jobstart(['cat'], {'rpc': v:true})") local catpath = eval('exepath("cat")') diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index b7fddc8f29..9579525502 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -126,6 +126,89 @@ function tests.check_workspace_configuration() } end +function tests.prepare_rename_nil() + skeleton { + on_init = function() + return { capabilities = { + renameProvider = true, + } } + end; + body = function() + notify('start') + expect_request('textDocument/prepareRename', function() + return nil, nil + end) + notify('shutdown') + end; + } +end + +function tests.prepare_rename_placeholder() + skeleton { + on_init = function() + return { capabilities = { + renameProvider = true, + } } + end; + body = function() + notify('start') + expect_request('textDocument/prepareRename', function() + return nil, {placeholder = 'placeholder'} + end) + expect_request('textDocument/rename', function(params) + assert_eq(params.newName, 'renameto') + return nil, nil + end) + notify('shutdown') + end; + } +end + +function tests.prepare_rename_range() + skeleton { + on_init = function() + return { capabilities = { + renameProvider = true, + } } + end; + body = function() + notify('start') + expect_request('textDocument/prepareRename', function() + return nil, { + start = { line = 1, character = 8 }, + ['end'] = { line = 1, character = 12 }, + } + end) + expect_request('textDocument/rename', function(params) + assert_eq(params.newName, 'renameto') + return nil, nil + end) + notify('shutdown') + end; + } +end + +function tests.prepare_rename_error() + skeleton { + on_init = function() + return { capabilities = { + renameProvider = true, + } } + end; + body = function() + notify('start') + expect_request('textDocument/prepareRename', function() + return {}, nil + end) + expect_request('textDocument/rename', function(params) + assert_eq(params.newName, 'renameto') + return nil, nil + end) + notify('shutdown') + end; + } +end + function tests.basic_check_capabilities() skeleton { on_init = function(params) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 0ea914880f..2bedbd1453 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -6,6 +6,7 @@ local funcs = helpers.funcs local meths = helpers.meths local dedent = helpers.dedent local command = helpers.command +local insert = helpers.insert local clear = helpers.clear local eq = helpers.eq local ok = helpers.ok @@ -1881,7 +1882,7 @@ describe('lua stdlib', function() end) it('vim.region', function() - helpers.insert(helpers.dedent( [[ + insert(helpers.dedent( [[ text tααt tααt text text tαxt txtα tex text tαxt tαxt @@ -1889,65 +1890,67 @@ describe('lua stdlib', function() eq({5,15}, exec_lua[[ return vim.region(0,{1,5},{1,14},'v',true)[1] ]]) end) - describe('vim.execute_on_keystroke', function() - it('should keep track of keystrokes', function() - helpers.insert([[hello world ]]) + describe('vim.on_key', function() + it('tracks keystrokes', function() + insert([[hello world ]]) exec_lua [[ - KeysPressed = {} + keys = {} - vim.register_keystroke_callback(function(buf) + vim.on_key(function(buf) if buf:byte() == 27 then buf = "<ESC>" end - table.insert(KeysPressed, buf) + table.insert(keys, buf) end) ]] - helpers.insert([[next 🤦 lines å ]]) + insert([[next 🤦 lines å ]]) -- It has escape in the keys pressed - eq('inext 🤦 lines å <ESC>', exec_lua [[return table.concat(KeysPressed, '')]]) + eq('inext 🤦 lines å <ESC>', exec_lua [[return table.concat(keys, '')]]) end) - it('should allow removing trackers.', function() - helpers.insert([[hello world]]) + it('allows removing on_key listeners', function() + insert([[hello world]]) exec_lua [[ - KeysPressed = {} + keys = {} - return vim.register_keystroke_callback(function(buf) + return vim.on_key(function(buf) if buf:byte() == 27 then buf = "<ESC>" end - table.insert(KeysPressed, buf) + table.insert(keys, buf) end, vim.api.nvim_create_namespace("logger")) ]] - helpers.insert([[next lines]]) + insert([[next lines]]) - exec_lua("vim.register_keystroke_callback(nil, vim.api.nvim_create_namespace('logger'))") + eq(1, exec_lua('return vim.on_key()')) + exec_lua("vim.on_key(nil, vim.api.nvim_create_namespace('logger'))") + eq(0, exec_lua('return vim.on_key()')) - helpers.insert([[more lines]]) + insert([[more lines]]) -- It has escape in the keys pressed - eq('inext lines<ESC>', exec_lua [[return table.concat(KeysPressed, '')]]) + eq('inext lines<ESC>', exec_lua [[return table.concat(keys, '')]]) end) - it('should not call functions that error again.', function() - helpers.insert([[hello world]]) + it('skips any function that caused an error', function() + insert([[hello world]]) exec_lua [[ - KeysPressed = {} + keys = {} - return vim.register_keystroke_callback(function(buf) + return vim.on_key(function(buf) if buf:byte() == 27 then buf = "<ESC>" end - table.insert(KeysPressed, buf) + table.insert(keys, buf) if buf == 'l' then error("Dumb Error") @@ -1955,35 +1958,30 @@ describe('lua stdlib', function() end) ]] - helpers.insert([[next lines]]) - helpers.insert([[more lines]]) + insert([[next lines]]) + insert([[more lines]]) -- Only the first letter gets added. After that we remove the callback - eq('inext l', exec_lua [[ return table.concat(KeysPressed, '') ]]) + eq('inext l', exec_lua [[ return table.concat(keys, '') ]]) end) - it('should process mapped keys, not unmapped keys', function() + it('processes mapped keys, not unmapped keys', function() exec_lua [[ - KeysPressed = {} + keys = {} vim.cmd("inoremap hello world") - vim.register_keystroke_callback(function(buf) + vim.on_key(function(buf) if buf:byte() == 27 then buf = "<ESC>" end - table.insert(KeysPressed, buf) + table.insert(keys, buf) end) ]] + insert("hello") - helpers.insert("hello") - - local next_status = exec_lua [[ - return table.concat(KeysPressed, '') - ]] - - eq("iworld<ESC>", next_status) + eq('iworld<ESC>', exec_lua[[return table.concat(keys, '')]]) end) end) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1d790cd470..a9ea26343d 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2202,4 +2202,90 @@ describe('LSP', function() eq(expected, qflist) end) end) + + describe('vim.lsp.buf.rename', function() + for _, test in ipairs({ + { + it = "does not attempt to rename on nil response", + name = "prepare_rename_nil", + expected_handlers = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; + }, + }, + { + it = "handles prepareRename placeholder response", + name = "prepare_rename_placeholder", + expected_handlers = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, NIL, {method="textDocument/rename", client_id=1, bufnr=1}}; + {NIL, {}, {method="start", client_id=1}}; + }, + expected_text = "placeholder", -- see fake lsp response + }, + { + it = "handles range response", + name = "prepare_rename_range", + expected_handlers = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, NIL, {method="textDocument/rename", client_id=1, bufnr=1}}; + {NIL, {}, {method="start", client_id=1}}; + }, + expected_text = "line", -- see test case and fake lsp response + }, + { + it = "handles error", + name = "prepare_rename_error", + expected_handlers = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, NIL, {method="textDocument/rename", client_id=1, bufnr=1}}; + {NIL, {}, {method="start", client_id=1}}; + }, + expected_text = "two", -- see test case + }, + }) do + it(test.it, function() + local client + test_rpc_server { + test_name = test.name; + on_init = function(_client) + client = _client + eq(true, client.resolved_capabilities().rename) + end; + on_setup = function() + exec_lua([=[ + local bufnr = vim.api.nvim_get_current_buf() + lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID) + vim.lsp._stubs = {} + vim.fn.input = function(prompt, text) + vim.lsp._stubs.input_prompt = prompt + vim.lsp._stubs.input_text = text + return 'renameto' -- expect this value in fake lsp + end + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'', 'this is line two'}) + vim.fn.cursor(2, 13) -- the space between "line" and "two" + ]=]) + end; + on_exit = function(code, signal) + eq(0, code, "exit code", fake_lsp_logfile) + eq(0, signal, "exit signal", fake_lsp_logfile) + end; + on_handler = function(err, result, ctx) + eq(table.remove(test.expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'start' then + exec_lua("vim.lsp.buf.rename()") + end + if ctx.method == 'shutdown' then + if test.expected_text then + eq("New Name: ", exec_lua("return vim.lsp._stubs.input_prompt")) + eq(test.expected_text, exec_lua("return vim.lsp._stubs.input_text")) + end + client.stop() + end + end; + } + end) + end + end) + end) |