diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/fixtures/fake-lsp-server.lua | 30 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 40 |
2 files changed, 66 insertions, 4 deletions
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index 0dc0c8c2db..aa47198f7a 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -67,10 +67,12 @@ local function expect_notification(method, params, ...) local message = read_message() assert_eq(method, message.method, ..., "expect_notification", "method") - assert_eq(params, message.params, - ..., "expect_notification", method, "params") - assert_eq({jsonrpc = "2.0"; method=method, params=params}, message, - ..., "expect_notification", "message") + if params then + assert_eq(params, message.params, + ..., "expect_notification", method, "params") + assert_eq({jsonrpc = "2.0"; method=method, params=params}, message, + ..., "expect_notification", "message") + end end local function expect_request(method, handler, ...) @@ -257,6 +259,26 @@ function tests.basic_check_capabilities() } end +function tests.text_document_save_did_open() + skeleton { + on_init = function() + return { + capabilities = { + textDocumentSync = { + save = true + } + } + } + end; + body = function() + notify('start') + expect_notification('textDocument/didOpen') + expect_notification('textDocument/didSave') + notify('shutdown') + end; + } +end + function tests.text_document_sync_save_bool() skeleton { on_init = function() diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index c166982052..cd7415de90 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -535,6 +535,46 @@ describe('LSP', function() } end) + it('saveas sends didOpen if filename changed', function() + local expected_handlers = { + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { NIL, {}, { method = 'start', client_id = 1 } }, + } + local client + test_rpc_server({ + test_name = 'text_document_save_did_open', + on_init = function(c) + client = c + end, + on_exit = function(code, signal) + 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 + local tmpfile_old = helpers.tmpname() + local tmpfile_new = helpers.tmpname() + os.remove(tmpfile_new) + exec_lua( + [=[ + local oldname, newname = ... + BUFFER = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_set_name(BUFFER, oldname) + vim.api.nvim_buf_set_lines(BUFFER, 0, -1, true, {"help me"}) + lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) + vim.api.nvim_buf_call(BUFFER, function() vim.cmd('saveas ' .. newname) end) + ]=], + tmpfile_old, + tmpfile_new + ) + else + client.stop() + end + end, + }) + end) + it('BufWritePost sends didSave including text if server capability is set', function() local expected_handlers = { {NIL, {}, {method="shutdown", client_id=1}}; |