diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-11-01 03:14:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 03:14:59 -0700 |
commit | 519d8deb08f369c559e7cbd61627c56db88623f1 (patch) | |
tree | f215ba8c220931f08bd2b67660680316df2fea49 /test | |
parent | 7ae86c1d4caffec57e2d4d44e40a9feba91d96dd (diff) | |
download | rneovim-519d8deb08f369c559e7cbd61627c56db88623f1.tar.gz rneovim-519d8deb08f369c559e7cbd61627c56db88623f1.tar.bz2 rneovim-519d8deb08f369c559e7cbd61627c56db88623f1.zip |
feat(lsp): add per-client commands (#16101)
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/fixtures/fake-lsp-server.lua | 14 | ||||
-rw-r--r-- | test/functional/plugin/lsp/codelens_spec.lua | 27 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 53 |
3 files changed, 67 insertions, 27 deletions
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index 523e1e11fd..5c0de50731 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -671,6 +671,20 @@ function tests.code_action_with_resolve() } end +function tests.clientside_commands() + skeleton { + on_init = function() + return { + capabilities = {} + } + end; + body = function() + notify('start') + notify('shutdown') + end; + } +end + -- Tests will be indexed by TEST_NAME local kill_timer = vim.loop.new_timer() diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index c8b75e65fc..ecc2f579b8 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -60,31 +60,4 @@ describe('vim.lsp.codelens', function() eq({[1] = {'Lens1', 'LspCodeLens'}}, virtual_text_chunks) end) - it('codelens uses client commands', function() - local fake_uri = "file:///fake/uri" - local cmd = exec_lua([[ - fake_uri = ... - local bufnr = vim.uri_to_bufnr(fake_uri) - vim.fn.bufload(bufnr) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'One line'}) - local lenses = { - { - range = { - start = { line = 0, character = 0, }, - ['end'] = { line = 0, character = 8 } - }, - command = { title = 'Lens1', command = 'Dummy' } - }, - } - vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) - local cmd_called = nil - vim.lsp.commands['Dummy'] = function(command) - cmd_called = command - end - vim.api.nvim_set_current_buf(bufnr) - vim.lsp.codelens.run() - return cmd_called - ]], fake_uri) - eq({ command = 'Dummy', title = 'Lens1' }, cmd) - end) end) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index e89bfcefbf..37fba02e0e 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2531,4 +2531,57 @@ describe('LSP', function() ) end) end) + describe('vim.lsp.codelens', function() + it('uses client commands', function() + local client + local expected_handlers = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; + } + test_rpc_server { + test_name = 'clientside_commands', + on_init = function(client_) + client = client_ + end, + on_setup = function() + 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(expected_handlers), {err, result, ctx}) + if ctx.method == 'start' then + local fake_uri = "file:///fake/uri" + local cmd = exec_lua([[ + fake_uri = ... + local bufnr = vim.uri_to_bufnr(fake_uri) + vim.fn.bufload(bufnr) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'One line'}) + local lenses = { + { + range = { + start = { line = 0, character = 0, }, + ['end'] = { line = 0, character = 8 } + }, + command = { title = 'Lens1', command = 'Dummy' } + }, + } + vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr}) + local cmd_called = nil + vim.lsp.commands['Dummy'] = function(command) + cmd_called = command + end + vim.api.nvim_set_current_buf(bufnr) + vim.lsp.codelens.run() + return cmd_called + ]], fake_uri) + eq({ command = 'Dummy', title = 'Lens1' }, cmd) + elseif ctx.method == 'shutdown' then + client.stop() + end + end + } + end) + end) end) |