diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
| commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
| tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/plugin/lsp_spec.lua | |
| parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
| download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip | |
refactor: format test/*
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
| -rw-r--r-- | test/functional/plugin/lsp_spec.lua | 2215 |
1 files changed, 1218 insertions, 997 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a6b3835dbc..86b9be79e0 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -32,14 +32,16 @@ local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile local test_rpc_server = lsp_helpers.test_rpc_server local function get_buf_option(name, bufnr) - bufnr = bufnr or "BUFFER" - return exec_lua( - string.format("return vim.api.nvim_get_option_value('%s', { buf = %s })", name, bufnr) - ) + bufnr = bufnr or 'BUFFER' + return exec_lua( + string.format("return vim.api.nvim_get_option_value('%s', { buf = %s })", name, bufnr) + ) end -- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 -if skip(is_os('win')) then return end +if skip(is_os('win')) then + return +end teardown(function() os.remove(fake_lsp_logfile) @@ -51,8 +53,9 @@ describe('LSP', function() -- Run an instance of nvim on the file which contains our "scripts". -- Pass TEST_NAME to pick the script. - local test_name = "basic_init" - exec_lua([=[ + local test_name = 'basic_init' + exec_lua( + [=[ lsp = require('vim.lsp') local test_name, fake_lsp_code, fake_lsp_logfile = ... function test__start_client() @@ -71,12 +74,16 @@ describe('LSP', function() } end TEST_CLIENT1 = test__start_client() - ]=], test_name, fake_lsp_code, fake_lsp_logfile) + ]=], + test_name, + fake_lsp_code, + fake_lsp_logfile + ) end) after_each(function() exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") - -- exec_lua("lsp.stop_all_clients(true)") + -- exec_lua("lsp.stop_all_clients(true)") end) describe('server_name specified', function() @@ -84,14 +91,20 @@ describe('LSP', function() retry(nil, 4000, function() eq(1, exec_lua('return #lsp.get_clients()')) end) - eq(2, exec_lua([[ + eq( + 2, + exec_lua([[ TEST_CLIENT2 = test__start_client() return TEST_CLIENT2 - ]])) - eq(3, exec_lua([[ + ]]) + ) + eq( + 3, + exec_lua([[ TEST_CLIENT3 = test__start_client() return TEST_CLIENT3 - ]])) + ]]) + ) retry(nil, 4000, function() eq(3, exec_lua('return #lsp.get_clients()')) end) @@ -128,21 +141,25 @@ describe('LSP', function() describe('lsp._cmd_parts test', function() local function _cmd_parts(input) - return exec_lua([[ + return exec_lua( + [[ lsp = require('vim.lsp') return lsp._cmd_parts(...) - ]], input) + ]], + input + ) end it('should valid cmd argument', function() - eq(true, pcall(_cmd_parts, {"nvim"})) - eq(true, pcall(_cmd_parts, {"nvim", "--head"})) + eq(true, pcall(_cmd_parts, { 'nvim' })) + eq(true, pcall(_cmd_parts, { 'nvim', '--head' })) end) it('should invalid cmd argument', function() - eq('.../lsp.lua:0: cmd: expected list, got nvim', - pcall_err(_cmd_parts, 'nvim')) - eq('.../lsp.lua:0: cmd argument: expected string, got number', - pcall_err(_cmd_parts, {'nvim', 1})) + eq('.../lsp.lua:0: cmd: expected list, got nvim', pcall_err(_cmd_parts, 'nvim')) + eq( + '.../lsp.lua:0: cmd argument: expected string, got number', + pcall_err(_cmd_parts, { 'nvim', 1 }) + ) end) end) end) @@ -151,54 +168,56 @@ describe('LSP', function() describe('basic_init test', function() after_each(function() stop() - exec_lua("lsp.stop_client(lsp.get_clients(), true)") + exec_lua('lsp.stop_client(lsp.get_clients(), true)') exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") end) it('should run correctly', function() local expected_handlers = { - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client, _) -- client is a dummy object which will queue up commands to be run -- once the server initializes. It can't accept lua callbacks or -- other types that may be unserializable for now. client.stop() - end; + end, -- If the program timed out, then code will be nil. on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, -- Note that NIL must be used here. -- on_handler(err, method, result, client_id) on_handler = function(...) - eq(table.remove(expected_handlers), {...}) - end; + eq(table.remove(expected_handlers), { ... }) + end, } end) it('should fail', function() local expected_handlers = { - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client) client.notify('test') client.stop() - end; + end, on_exit = function(code, signal) - eq(101, code, "exit code") -- See fake-lsp-server.lua - eq(0, signal, "exit signal") - assert_log(pesc([[assert_eq failed: left == "\"shutdown\"", right == "\"test\""]]), - fake_lsp_logfile) - end; + eq(101, code, 'exit code') -- See fake-lsp-server.lua + eq(0, signal, 'exit signal') + assert_log( + pesc([[assert_eq failed: left == "\"shutdown\"", right == "\"test\""]]), + fake_lsp_logfile + ) + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) @@ -218,10 +237,12 @@ describe('LSP', function() }) end) - it("should set the client's offset_encoding when positionEncoding capability is supported", function() - clear() - exec_lua(create_server_definition) - local result = exec_lua([[ + it( + "should set the client's offset_encoding when positionEncoding capability is supported", + function() + clear() + exec_lua(create_server_definition) + local result = exec_lua([[ local server = _create_server({ capabilities = { positionEncoding = "utf-8" @@ -243,8 +264,9 @@ describe('LSP', function() end return client.offset_encoding ]]) - eq('utf-8', result) - end) + eq('utf-8', result) + end + ) it('should succeed with manual shutdown', function() if is_ci() then @@ -254,68 +276,68 @@ describe('LSP', function() return end local expected_handlers = { - {NIL, {}, {method="shutdown", bufnr=1, client_id=1}}; - {NIL, {}, {method="test", client_id=1}}; + { NIL, {}, { method = 'shutdown', bufnr = 1, client_id = 1 } }, + { NIL, {}, { method = 'test', client_id = 1 } }, } test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_init = function(client) eq(0, client.server_capabilities().textDocumentSync.change) client.request('shutdown') client.notify('exit') client.stop() - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) it('should detach buffer in response to nvim_buf_detach', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="finish", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'finish', client_id = 1 } }, } local client test_rpc_server { - test_name = "basic_finish"; + test_name = 'basic_finish', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) ]] - eq(true, exec_lua("return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")) - eq(true, exec_lua("return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)")) + eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)')) + eq(true, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)')) exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end; + end, on_init = function(_client) client = _client client.notify('finish') - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'finish' then - exec_lua("return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)") - eq(false, exec_lua("return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)")) + exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') + eq(false, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)')) client.stop() end - end; + end, } end) it('should fire autocommands on attach and detach', function() local client test_rpc_server { - test_name = "basic_init"; + test_name = 'basic_init', on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) @@ -332,69 +354,75 @@ describe('LSP', function() end, }) ]] - end; + end, on_init = function(_client) client = _client - eq(true, exec_lua("return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)")) + eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)')) client.notify('finish') - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'finish' then eq('basic_init', meths.get_var('lsp_attached')) - exec_lua("return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)") + exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') eq('basic_init', meths.get_var('lsp_detached')) client.stop() end - end; + end, } end) it('should set default options on attach', function() local client test_rpc_server { - test_name = "set_defaults_all_capabilities"; + test_name = 'set_defaults_all_capabilities', on_init = function(_client) client = _client exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) ]] - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'test' then - eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc")) - eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc")) - eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr")) - eq('', get_buf_option("keywordprg")) - eq(true, exec_lua[[ + eq('v:lua.vim.lsp.tagfunc', get_buf_option('tagfunc')) + eq('v:lua.vim.lsp.omnifunc', get_buf_option('omnifunc')) + eq('v:lua.vim.lsp.formatexpr()', get_buf_option('formatexpr')) + eq('', get_buf_option('keywordprg')) + eq( + true, + exec_lua [[ local keymap vim.api.nvim_buf_call(BUFFER, function() keymap = vim.fn.maparg("K", "n", false, true) end) return keymap.callback == vim.lsp.buf.hover - ]]) + ]] + ) client.stop() end - end; + end, on_exit = function(_, _) - eq('', get_buf_option("tagfunc")) - eq('', get_buf_option("omnifunc")) - eq('', get_buf_option("formatexpr")) - eq('', exec_lua[[ + eq('', get_buf_option('tagfunc')) + eq('', get_buf_option('omnifunc')) + eq('', get_buf_option('formatexpr')) + eq( + '', + exec_lua [[ local keymap vim.api.nvim_buf_call(BUFFER, function() keymap = vim.fn.maparg("K", "n", false, false) end) return keymap - ]]) - end; + ]] + ) + end, } end) it('should overwrite options set by ftplugins', function() local client test_rpc_server { - test_name = "set_defaults_all_capabilities"; + test_name = 'set_defaults_all_capabilities', on_init = function(_client) client = _client exec_lua [[ @@ -406,35 +434,35 @@ describe('LSP', function() ]] -- Sanity check to ensure that some values are set after setting filetype. - eq('v:lua.require\'man\'.goto_tag', get_buf_option("tagfunc", "BUFFER_1")) - eq('xmlcomplete#CompleteTags', get_buf_option("omnifunc", "BUFFER_2")) - eq('xmlformat#Format()', get_buf_option("formatexpr", "BUFFER_2")) + eq("v:lua.require'man'.goto_tag", get_buf_option('tagfunc', 'BUFFER_1')) + eq('xmlcomplete#CompleteTags', get_buf_option('omnifunc', 'BUFFER_2')) + eq('xmlformat#Format()', get_buf_option('formatexpr', 'BUFFER_2')) exec_lua [[ lsp.buf_attach_client(BUFFER_1, TEST_RPC_CLIENT_ID) lsp.buf_attach_client(BUFFER_2, TEST_RPC_CLIENT_ID) ]] - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'test' then - eq('v:lua.vim.lsp.tagfunc', get_buf_option("tagfunc", "BUFFER_1")) - eq('v:lua.vim.lsp.omnifunc', get_buf_option("omnifunc", "BUFFER_2")) - eq('v:lua.vim.lsp.formatexpr()', get_buf_option("formatexpr", "BUFFER_2")) + eq('v:lua.vim.lsp.tagfunc', get_buf_option('tagfunc', 'BUFFER_1')) + eq('v:lua.vim.lsp.omnifunc', get_buf_option('omnifunc', 'BUFFER_2')) + eq('v:lua.vim.lsp.formatexpr()', get_buf_option('formatexpr', 'BUFFER_2')) client.stop() end - end; + end, on_exit = function(_, _) - eq('', get_buf_option("tagfunc", "BUFFER_1")) - eq('', get_buf_option("omnifunc", "BUFFER_2")) - eq('', get_buf_option("formatexpr", "BUFFER_2")) - end; + eq('', get_buf_option('tagfunc', 'BUFFER_1')) + eq('', get_buf_option('omnifunc', 'BUFFER_2')) + eq('', get_buf_option('formatexpr', 'BUFFER_2')) + end, } end) it('should not overwrite user-defined options', function() local client test_rpc_server { - test_name = "set_defaults_all_capabilities"; + test_name = 'set_defaults_all_capabilities', on_init = function(_client) client = _client exec_lua [[ @@ -444,20 +472,20 @@ describe('LSP', function() vim.api.nvim_set_option_value('formatexpr', 'fex', { buf = BUFFER }) lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) ]] - end; + end, on_handler = function(_, _, ctx) if ctx.method == 'test' then - eq('tfu', get_buf_option("tagfunc")) - eq('ofu', get_buf_option("omnifunc")) - eq('fex', get_buf_option("formatexpr")) + eq('tfu', get_buf_option('tagfunc')) + eq('ofu', get_buf_option('omnifunc')) + eq('fex', get_buf_option('formatexpr')) client.stop() end - end; + end, on_exit = function(_, _) - eq('tfu', get_buf_option("tagfunc")) - eq('ofu', get_buf_option("omnifunc")) - eq('fex', get_buf_option("formatexpr")) - end; + eq('tfu', get_buf_option('tagfunc')) + eq('ofu', get_buf_option('omnifunc')) + eq('fex', get_buf_option('formatexpr')) + end, } end) @@ -481,34 +509,40 @@ describe('LSP', function() num_attached_after = num_attached_after, } ]]) - eq(true, result ~= nil, "exec_lua must return result") + eq(true, result ~= nil, 'exec_lua must return result') eq(1, result.num_attached_before) eq(0, result.num_attached_after) end) it('client should return settings via workspace/configuration handler', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, { items = { - { section = "testSetting1" }; - { section = "testSetting2" }; - { section = "test.Setting3" }; - { section = "test.Setting4" }; - }}, { method="workspace/configuration", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { + NIL, + { + items = { + { section = 'testSetting1' }, + { section = 'testSetting2' }, + { section = 'test.Setting3' }, + { section = 'test.Setting4' }, + }, + }, + { method = 'workspace/configuration', client_id = 1 }, + }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "check_workspace_configuration"; + test_name = 'check_workspace_configuration', on_init = function(_client) client = _client - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") + 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) @@ -519,24 +553,32 @@ describe('LSP', function() }]=]) end if ctx.method == 'workspace/configuration' then - local server_result = exec_lua([=[ + local server_result = exec_lua( + [=[ local method, params = ... - return require'vim.lsp.handlers'['workspace/configuration'](err, params, {method=method, client_id=TEST_RPC_CLIENT_ID})]=], ctx.method, 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 ctx.method == 'shutdown' then client.stop() end - end; + end, } end) - it('workspace/configuration returns NIL per section if client was started without config.settings', function() - local result = nil - test_rpc_server { - test_name = 'basic_init'; - on_init = function(c) c.stop() end, - on_setup = function() - result = exec_lua [[ + it( + 'workspace/configuration returns NIL per section if client was started without config.settings', + function() + local result = nil + test_rpc_server { + test_name = 'basic_init', + on_init = function(c) + c.stop() + end, + on_setup = function() + result = exec_lua [[ local result = { items = { {section = 'foo'}, @@ -545,52 +587,53 @@ describe('LSP', function() } return vim.lsp.handlers['workspace/configuration'](nil, result, {client_id=TEST_RPC_CLIENT_ID}) ]] - end - } - eq({ NIL, NIL }, result) - end) + end, + } + eq({ NIL, NIL }, result) + end + ) it('should verify capabilities sent', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, } test_rpc_server { - test_name = "basic_check_capabilities"; + test_name = 'basic_check_capabilities', on_init = function(client) client.stop() local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) - eq({includeText = false}, client.server_capabilities().textDocumentSync.save) + eq({ includeText = false }, client.server_capabilities().textDocumentSync.save) eq(false, client.server_capabilities().codeLensProvider) - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) it('BufWritePost sends didSave with bool textDocumentSync.save', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "text_document_sync_save_bool"; + test_name = 'text_document_sync_save_bool', on_init = function(c) client = c - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") - if ctx.method == "start" then + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') + if ctx.method == 'start' then exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) @@ -599,7 +642,7 @@ describe('LSP', function() else client.stop() end - end; + end, } end) @@ -664,7 +707,7 @@ describe('LSP', function() local messages = result.messages eq('textDocument/willSave', messages[3].method) eq('textDocument/willSaveWaitUntil', messages[4].method) - eq({'Hello'}, result.lines) + eq({ 'Hello' }, result.lines) end) it('saveas sends didOpen if filename changed', function() @@ -709,22 +752,22 @@ describe('LSP', function() it('BufWritePost sends didSave including text if server capability is set', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - {NIL, {}, {method="start", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, } local client test_rpc_server { - test_name = "text_document_sync_save_includeText"; + test_name = 'text_document_sync_save_includeText', on_init = function(c) client = c - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(err, result, ctx) - eq(table.remove(expected_handlers), {err, result, ctx}, "expected handler") - if ctx.method == "start" then + eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') + if ctx.method == 'start' then exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() vim.api.nvim_buf_set_lines(BUFFER, 0, -1, true, {"help me"}) @@ -734,16 +777,16 @@ describe('LSP', function() else client.stop() end - end; + end, } end) it('client.supports_methods() should validate capabilities', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, } test_rpc_server { - test_name = "capabilities_for_client_supports_method"; + test_name = 'capabilities_for_client_supports_method', on_init = function(client) client.stop() local expected_sync_capabilities = { @@ -761,268 +804,285 @@ describe('LSP', function() eq(true, client.server_capabilities().codeLensProvider.resolveProvider) -- known methods for resolved capabilities - eq(true, client.supports_method("textDocument/hover")) - eq(false, client.supports_method("textDocument/definition")) + eq(true, client.supports_method('textDocument/hover')) + eq(false, client.supports_method('textDocument/definition')) -- unknown methods are assumed to be supported. - eq(true, client.supports_method("unknown-method")) - end; + eq(true, client.supports_method('unknown-method')) + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) it('should not call unsupported_method when trying to call an unsupported method', function() local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; + { NIL, {}, { method = 'shutdown', client_id = 1 } }, } test_rpc_server { - test_name = "capabilities_for_client_supports_method"; + test_name = 'capabilities_for_client_supports_method', on_setup = function() - exec_lua([=[ + exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) vim.lsp.handlers['textDocument/typeDefinition'] = function() end ]=]) - end; + end, on_init = function(client) client.stop() - exec_lua("vim.lsp.buf.type_definition()") + exec_lua('vim.lsp.buf.type_definition()') exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, } end) - it('should not call unsupported_method when no client and trying to call an unsupported method', function() - local expected_handlers = { - {NIL, {}, {method="shutdown", client_id=1}}; - } - test_rpc_server { - test_name = "capabilities_for_client_supports_method"; - on_setup = function() + it( + 'should not call unsupported_method when no client and trying to call an unsupported method', + function() + local expected_handlers = { + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + } + test_rpc_server { + test_name = 'capabilities_for_client_supports_method', + on_setup = function() exec_lua([=[ vim.lsp.handlers['textDocument/typeDefinition'] = function() end ]=]) - end; - on_init = function(client) - client.stop() - exec_lua("vim.lsp.buf.type_definition()") - end; - on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - end; - on_handler = function(...) - eq(table.remove(expected_handlers), {...}, "expected handler") - end; - } - end) + end, + on_init = function(client) + client.stop() + exec_lua('vim.lsp.buf.type_definition()') + end, + on_exit = function(code, signal) + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + end, + on_handler = function(...) + eq(table.remove(expected_handlers), { ... }, 'expected handler') + end, + } + end + ) it('should not forward RequestCancelled to callback', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, } local client test_rpc_server { - test_name = "check_forward_request_cancelled"; + test_name = 'check_forward_request_cancelled', on_init = function(_client) - _client.request("error_code_test") + _client.request('error_code_test') client = _client - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler") - if ctx.method == 'finish' then client.stop() end - end; + eq(table.remove(expected_handlers), { err, {}, ctx }, 'expected handler') + if ctx.method == 'finish' then + client.stop() + end + end, } end) it('should forward ContentModified to callback', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; - {{code = -32801}, NIL, {method = "error_code_test", bufnr=1, client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, + { { code = -32801 }, NIL, { method = 'error_code_test', bufnr = 1, client_id = 1 } }, } local client test_rpc_server { - test_name = "check_forward_content_modified"; + test_name = 'check_forward_content_modified', on_init = function(_client) - _client.request("error_code_test") + _client.request('error_code_test') client = _client - end; + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, _, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, _, ctx }, 'expected handler') -- if ctx.method == 'error_code_test' then client.notify("finish") end - if ctx.method ~= 'finish' then client.notify('finish') end - if ctx.method == 'finish' then client.stop() end - end; + if ctx.method ~= 'finish' then + client.notify('finish') + end + if ctx.method == 'finish' then + client.stop() + end + end, } end) it('should track pending requests to the language server', function() local expected_handlers = { - {NIL, {}, {method="finish", client_id=1}}; - {NIL, {}, {method="slow_request", bufnr=1, client_id=1}}; + { NIL, {}, { method = 'finish', client_id = 1 } }, + { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } local client test_rpc_server { - test_name = "check_pending_request_tracked"; + test_name = 'check_pending_request_tracked', on_init = function(_client) client = _client - client.request("slow_request") + client.request('slow_request') local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) - eq("slow_request", request.method) - eq("pending", request.type) - client.notify("release") - end; + eq('slow_request', request.method) + eq('pending', request.type) + client.notify('release') + end, on_exit = function(code, signal) - eq(0, code, "exit code") - eq(0, signal, "exit signal") - eq(0, #expected_handlers, "did not call expected handler") - end; + eq(0, code, 'exit code') + eq(0, signal, 'exit signal') + eq(0, #expected_handlers, 'did not call expected handler') + end, on_handler = function(err, _, ctx) - eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler") + eq(table.remove(expected_handlers), { err, {}, ctx }, 'expected handler') if ctx.method == 'slow_request' then local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=]) |