diff options
| author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-09-05 10:27:52 -0700 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2021-09-26 10:25:17 -0700 |
| commit | cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0 (patch) | |
| tree | 980dbf25f4342e9cf4b616f6c242df3355963ec8 /test/functional/plugin/lsp_spec.lua | |
| parent | f8e0011534a3f94cfd341fd9bfce1bcf9b1b7b73 (diff) | |
| download | rneovim-cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0.tar.gz rneovim-cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0.tar.bz2 rneovim-cd8f6c5fb7858d8981fdfb2067bddb3eb86c13d0.zip | |
feat(lsp)!: change handler signature #15504
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
| -rw-r--r-- | test/functional/plugin/lsp_spec.lua | 203 |
1 files changed, 102 insertions, 101 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index d1a34e8d9b..da96ff6a5f 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -216,7 +216,7 @@ describe('LSP', function() it('should run correctly', function() local expected_handlers = { - {NIL, "test", {}, 1}; + {NIL, {}, {method="test", client_id=1}}; } test_rpc_server { test_name = "basic_init"; @@ -241,7 +241,7 @@ describe('LSP', function() it('should fail', function() local expected_handlers = { - {NIL, "test", {}, 1}; + {NIL, {}, {method="test", client_id=1}}; } test_rpc_server { test_name = "basic_init"; @@ -269,8 +269,8 @@ describe('LSP', function() return end local expected_handlers = { - {NIL, "shutdown", {}, 1, NIL}; - {NIL, "test", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="test", client_id=1}}; } test_rpc_server { test_name = "basic_init"; @@ -292,12 +292,12 @@ describe('LSP', function() it('client should return settings via workspace/configuration handler', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "workspace/configuration", { items = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, { items = { { section = "testSetting1" }; { section = "testSetting2" }; - }}, 1}; - {NIL, "start", {}, 1}; + }}, { method="workspace/configuration", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -309,9 +309,9 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'start' then + on_handler = function(err, result, ctx) + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'start' then exec_lua([=[ local client = vim.lsp.get_client_by_id(TEST_RPC_CLIENT_ID) client.config.settings = { @@ -319,13 +319,13 @@ describe('LSP', function() testSetting2 = false; }]=]) end - if method == 'workspace/configuration' then - local result = exec_lua([=[ + if ctx.method == 'workspace/configuration' then + local server_result = exec_lua([=[ local method, params = ... - return require'vim.lsp.handlers'['workspace/configuration'](err, method, params, TEST_RPC_CLIENT_ID)]=], method, params) - client.notify('workspace/configuration', result) + return require'vim.lsp.handlers'['workspace/configuration'](err, params, {method=method, client_id=TEST_RPC_CLIENT_ID})]=], ctx.method, result) + client.notify('workspace/configuration', server_result) end - if method == 'shutdown' then + if ctx.method == 'shutdown' then client.stop() end end; @@ -335,19 +335,19 @@ describe('LSP', function() clear_notrace() fake_lsp_server_setup('workspace/configuration no settings') eq({ NIL, NIL, }, exec_lua [[ - local params = { + local result = { items = { {section = 'foo'}, {section = 'bar'}, } } - return vim.lsp.handlers['workspace/configuration'](nil, nil, params, TEST_RPC_CLIENT_ID) + return vim.lsp.handlers['workspace/configuration'](nil, result, {client_id=TEST_RPC_CLIENT_ID}) ]]) end) it('should verify capabilities sent', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; } test_rpc_server { test_name = "basic_check_capabilities"; @@ -371,7 +371,7 @@ describe('LSP', function() it('client.supports_methods() should validate capabilities', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; } test_rpc_server { test_name = "capabilities_for_client_supports_method"; @@ -405,7 +405,7 @@ describe('LSP', function() it('should call unsupported_method when trying to call an unsupported method', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; } test_rpc_server { test_name = "capabilities_for_client_supports_method"; @@ -413,7 +413,8 @@ describe('LSP', function() exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) - vim.lsp.handlers['textDocument/typeDefinition'] = function(err, method) + vim.lsp.handlers['textDocument/typeDefinition'] = function(err, result, ctx) + local method = ctx.method vim.lsp._last_lsp_handler = { err = err; method = method } end vim.lsp._unsupported_method = function(method) @@ -446,7 +447,7 @@ describe('LSP', function() it('shouldn\'t call unsupported_method when no client and trying to call an unsupported method', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; } test_rpc_server { test_name = "capabilities_for_client_supports_method"; @@ -479,8 +480,8 @@ describe('LSP', function() it('should not send didOpen if the buffer closes before init', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; } local client test_rpc_server { @@ -511,9 +512,9 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + on_handler = function(err, result, ctx) + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -522,9 +523,9 @@ describe('LSP', function() it('should check the body sent attaching before init', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -554,12 +555,12 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -568,9 +569,9 @@ describe('LSP', function() it('should check the body sent attaching after init', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -597,12 +598,12 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -611,9 +612,9 @@ describe('LSP', function() it('should check the body and didChange full', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -640,8 +641,8 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then exec_lua [[ vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { "boop"; @@ -649,8 +650,8 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -659,9 +660,9 @@ describe('LSP', function() it('should check the body and didChange full with noeol', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -689,8 +690,8 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then exec_lua [[ vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { "boop"; @@ -698,8 +699,8 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -708,9 +709,9 @@ describe('LSP', function() it('should check the body and didChange incremental', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -738,8 +739,8 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then exec_lua [[ vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { "123boop"; @@ -747,8 +748,8 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -758,9 +759,9 @@ describe('LSP', function() -- TODO(askhan) we don't support full for now, so we can disable these tests. pending('should check the body and didChange incremental normal mode editing', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -787,13 +788,13 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then helpers.command("normal! 1Go") client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -802,9 +803,9 @@ describe('LSP', function() it('should check the body and didChange full with 2 changes', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -831,8 +832,8 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result, ctx) + if ctx.method == 'start' then exec_lua [[ vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { "321"; @@ -843,8 +844,8 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -853,9 +854,9 @@ describe('LSP', function() it('should check the body and didChange full lifecycle', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -882,8 +883,8 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - if method == 'start' then + on_handler = function(err, result,ctx) + if ctx.method == 'start' then exec_lua [[ vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { "321"; @@ -895,8 +896,8 @@ describe('LSP', function() ]] client.notify('finish') end - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -907,9 +908,9 @@ describe('LSP', function() describe("parsing tests", function() it('should handle invalid content-length correctly', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "start", {}, 1}; + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -924,22 +925,22 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") + on_handler = function(err, result, ctx) + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") end; } end) it('should not trim vim.NIL from the end of a list', function() local expected_handlers = { - {NIL, "shutdown", {}, 1}; - {NIL, "finish", {}, 1}; - {NIL, "workspace/executeCommand", { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="finish", client_id=1}}; + {NIL,{ arguments = { "EXTRACT_METHOD", {metadata = {}}, 3, 0, 6123, NIL }, command = "refactor.perform", title = "EXTRACT_METHOD" - }, 1}; - {NIL, "start", {}, 1}; + }, {method="workspace/executeCommand", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; } local client test_rpc_server { @@ -963,9 +964,9 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_handler = function(err, method, params, client_id) - eq(table.remove(expected_handlers), {err, method, params, client_id}, "expected handler") - if method == 'finish' then + on_handler = function(err, result, ctx) + eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + if ctx.method == 'finish' then client.stop() end end; @@ -1976,7 +1977,7 @@ describe('LSP', function() describe('vim.lsp.buf.outgoing_calls', function() it('does nothing for an empty response', function() local qflist_count = exec_lua([=[ - require'vim.lsp.handlers'['callHierarchy/outgoingCalls']() + require'vim.lsp.handlers'['callHierarchy/outgoingCalls'](nil, nil, {}, nil) return #vim.fn.getqflist() ]=]) eq(0, qflist_count) @@ -2023,7 +2024,7 @@ describe('LSP', function() } } } local handler = require'vim.lsp.handlers'['callHierarchy/outgoingCalls'] - handler(nil, nil, rust_analyzer_response) + handler(nil, rust_analyzer_response, {}) return vim.fn.getqflist() ]=]) @@ -2047,7 +2048,7 @@ describe('LSP', function() describe('vim.lsp.buf.incoming_calls', function() it('does nothing for an empty response', function() local qflist_count = exec_lua([=[ - require'vim.lsp.handlers'['callHierarchy/incomingCalls']() + require'vim.lsp.handlers'['callHierarchy/incomingCalls'](nil, nil, {}) return #vim.fn.getqflist() ]=]) eq(0, qflist_count) @@ -2095,7 +2096,7 @@ describe('LSP', function() } } local handler = require'vim.lsp.handlers'['callHierarchy/incomingCalls'] - handler(nil, nil, rust_analyzer_response) + handler(nil, rust_analyzer_response, {}) return vim.fn.getqflist() ]=]) |