diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-08-28 00:12:30 -0400 |
---|---|---|
committer | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-09-05 10:04:30 -0700 |
commit | df17d7844ed7dedcb80f9405f7078a046a12524a (patch) | |
tree | aa1cd7c325aefe6ad6d48a95316df08fcaf25a11 /test/functional | |
parent | 5d633546bf5990d03e4b4dc1df213f88316115e6 (diff) | |
download | rneovim-df17d7844ed7dedcb80f9405f7078a046a12524a.tar.gz rneovim-df17d7844ed7dedcb80f9405f7078a046a12524a.tar.bz2 rneovim-df17d7844ed7dedcb80f9405f7078a046a12524a.zip |
feat(lsp)!: change handler signature
Previously, the handler signature was:
function(err, method, params, client_id, bufnr, config)
In order to better support external plugins that wish to extend the
protocol, there is other information which would be advantageous to
forward to the client, such as the original params of the request that
generated the callback.
In order to do this, we would need to break symmetry of the handlers, to
add an additional "params" as the 7th argument.
Instead, this PR changes the signature of the handlers to:
function(err, result, ctx, config)
where ctx (the context) includes params, client_id, and bufnr. This also leaves
flexibility for future use-cases.
BREAKING_CHANGE: changes the signature of the built-in client handlers, requiring
updating handler calls
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/plugin/lsp/codelens_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/plugin/lsp/diagnostic_spec.lua | 72 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 203 |
3 files changed, 139 insertions, 138 deletions
diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index 2dc9b8f960..e48a0ad260 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -32,7 +32,7 @@ describe('vim.lsp.codelens', function() command = { title = 'Lens1', command = 'Dummy' } }, } - vim.lsp.codelens.on_codelens(nil, 'textDocument/codeLens', lenses, 1, bufnr) + vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) ]], bufnr) local stored_lenses = exec_lua('return vim.lsp.codelens.get(...)', bufnr) diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 7359ee4bce..e4fe1c1992 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -205,8 +205,8 @@ describe('vim.lsp.diagnostic', function() make_warning("Warning 1", 2, 1, 2, 5), } - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_1_diags }, 1) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_2_diags }, 2) + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_1_diags }, {client_id=1}) + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_2_diags }, {client_id=2}) return { vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1), vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2), @@ -251,8 +251,8 @@ describe('vim.lsp.diagnostic', function() make_warning("Warning 1", 2, 1, 2, 5), } - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_1_diags }, 1) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_2_diags }, 2) + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_1_diags }, {client_id=1}) + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_2_diags }, {client_id=2}) vim.lsp.diagnostic.disable(diagnostic_bufnr, 1) @@ -290,8 +290,8 @@ describe('vim.lsp.diagnostic', function() make_warning("Warning 1", 2, 1, 2, 5), } - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_1_diags }, 1) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_2_diags }, 2) + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_1_diags }, {client_id=1}) + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_2_diags }, {client_id=2}) return { vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1), vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2), @@ -467,14 +467,14 @@ describe('vim.lsp.diagnostic', function() it('should return all diagnostics when no severity is supplied', function() eq(2, exec_lua [[ - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 5), make_error("Error On Other Line", 2, 1, 1, 5), } - }, 1) + }, {client_id=1}) return #vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1) ]]) @@ -482,7 +482,7 @@ describe('vim.lsp.diagnostic', function() it('should return only requested diagnostics when severity_limit is supplied', function() eq(2, exec_lua [[ - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = { make_error("Error 1", 1, 1, 1, 5), @@ -490,7 +490,7 @@ describe('vim.lsp.diagnostic', function() make_information("Ignored information", 1, 1, 2, 5), make_error("Error On Other Line", 2, 1, 1, 5), } - }, 1) + }, {client_id=1}) return #vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1, { severity_limit = "Warning" }) ]]) @@ -502,12 +502,12 @@ describe('vim.lsp.diagnostic', function() exec_lua [[ vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = function() return true end, - })(nil, nil, { + })(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) ]] @@ -519,12 +519,12 @@ describe('vim.lsp.diagnostic', function() exec_lua [[ vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = function() return false end, - })(nil, nil, { + })(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) ]] @@ -541,12 +541,12 @@ describe('vim.lsp.diagnostic', function() exec_lua [[ vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { update_in_insert = false, - })(nil, nil, { + })(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) ]] @@ -583,12 +583,12 @@ describe('vim.lsp.diagnostic', function() return SetVirtualTextOriginal(...) end - PublishDiagnostics(nil, nil, { + PublishDiagnostics(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) ]] @@ -637,12 +637,12 @@ describe('vim.lsp.diagnostic', function() return SetVirtualTextOriginal(...) end - PublishDiagnostics(nil, nil, { + PublishDiagnostics(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) ]] @@ -679,12 +679,12 @@ describe('vim.lsp.diagnostic', function() exec_lua [[ vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { update_in_insert = true, - })(nil, nil, { + })(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) ]] @@ -709,12 +709,12 @@ describe('vim.lsp.diagnostic', function() }, }) - PublishDiagnostics(nil, nil, { + PublishDiagnostics(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) return vim.api.nvim_buf_get_extmarks( @@ -746,12 +746,12 @@ describe('vim.lsp.diagnostic', function() end, }) - PublishDiagnostics(nil, nil, { + PublishDiagnostics(nil, { uri = fake_uri, diagnostics = { make_error('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) return vim.api.nvim_buf_get_extmarks( @@ -779,12 +779,12 @@ describe('vim.lsp.diagnostic', function() }, }) - PublishDiagnostics(nil, nil, { + PublishDiagnostics(nil, { uri = fake_uri, diagnostics = { make_warning('Delayed Diagnostic', 4, 4, 4, 4), } - }, 1 + }, {client_id=1} ) return count_of_extmarks_for_client(diagnostic_bufnr, 1) @@ -870,10 +870,10 @@ describe('vim.lsp.diagnostic', function() } vim.api.nvim_win_set_buf(0, diagnostic_bufnr) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = diagnostics - }, 1 + }, {client_id=1} ) vim.lsp.diagnostic.set_signs(diagnostics, diagnostic_bufnr, 1) @@ -895,13 +895,13 @@ describe('vim.lsp.diagnostic', function() local loc_list = exec_lua [[ vim.api.nvim_win_set_buf(0, diagnostic_bufnr) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = { make_error('Farther Diagnostic', 4, 4, 4, 4), make_error('Lower Diagnostic', 1, 1, 1, 1), } - }, 1 + }, {client_id=1} ) vim.lsp.diagnostic.set_loclist() @@ -916,20 +916,20 @@ describe('vim.lsp.diagnostic', function() local loc_list = exec_lua [[ vim.api.nvim_win_set_buf(0, diagnostic_bufnr) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = { make_error('Lower Diagnostic', 1, 1, 1, 1), } - }, 1 + }, {client_id=1} ) - vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { + vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = { make_warning('Farther Diagnostic', 4, 4, 4, 4), } - }, 2 + }, {client_id=2} ) vim.lsp.diagnostic.set_loclist() diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 3c4d01ae74..aa2d8db206 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -217,7 +217,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"; @@ -242,7 +242,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"; @@ -270,8 +270,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"; @@ -293,12 +293,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 { @@ -310,9 +310,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 = { @@ -320,13 +320,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; @@ -336,19 +336,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"; @@ -372,7 +372,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"; @@ -406,7 +406,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"; @@ -414,7 +414,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) @@ -447,7 +448,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"; @@ -480,8 +481,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 { @@ -512,9 +513,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; @@ -523,9 +524,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 { @@ -555,12 +556,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; @@ -569,9 +570,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 { @@ -598,12 +599,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; @@ -612,9 +613,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 { @@ -641,8 +642,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"; @@ -650,8 +651,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; @@ -660,9 +661,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 { @@ -690,8 +691,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"; @@ -699,8 +700,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; @@ -709,9 +710,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 { @@ -739,8 +740,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"; @@ -748,8 +749,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; @@ -759,9 +760,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 { @@ -788,13 +789,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; @@ -803,9 +804,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 { @@ -832,8 +833,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"; @@ -844,8 +845,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; @@ -854,9 +855,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 { @@ -883,8 +884,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"; @@ -896,8 +897,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; @@ -908,9 +909,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 { @@ -925,22 +926,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 { @@ -964,9 +965,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; @@ -1980,7 +1981,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) @@ -2027,7 +2028,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() ]=]) @@ -2053,7 +2054,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) @@ -2101,7 +2102,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() ]=]) |