diff options
-rw-r--r-- | runtime/lua/vim/lsp.lua | 13 | ||||
-rw-r--r-- | test/functional/fixtures/lsp-test-rpc-server.lua | 53 | ||||
-rw-r--r-- | test/functional/plugin/lsp/lsp_spec.lua | 48 |
3 files changed, 102 insertions, 12 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 9dbe03dace..0c1a145c04 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -23,7 +23,6 @@ local lsp = { -- format_rpc_error = lsp_rpc.format_rpc_error; } --- TODO consider whether 'eol' or 'fixeol' should change the nvim_buf_get_lines that send. -- TODO improve handling of scratch buffers with LSP attached. local function resolve_bufnr(bufnr) @@ -175,6 +174,14 @@ local function validate_client_config(config) } end +local function buf_get_full_text(bufnr) + local text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, true), '\n') + if nvim_buf_get_option(bufnr, 'eol') then + text = text .. '\n' + end + return text +end + local function text_document_did_open_handler(bufnr, client) if not client.resolved_capabilities.text_document_open_close then return @@ -188,7 +195,7 @@ local function text_document_did_open_handler(bufnr, client) uri = vim.uri_from_bufnr(bufnr); -- TODO make sure our filetypes are compatible with languageId names. languageId = nvim_buf_get_option(bufnr, 'filetype'); - text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, false), '\n'); + text = buf_get_full_text(bufnr); } } client.notify('textDocument/didOpen', params) @@ -551,7 +558,7 @@ do end) local full_changes = once(function() return { - text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, false), "\n"); + text = buf_get_full_text(bufnr); }; end) local uri = vim.uri_from_bufnr(bufnr) diff --git a/test/functional/fixtures/lsp-test-rpc-server.lua b/test/functional/fixtures/lsp-test-rpc-server.lua index 971e61b072..798883ced0 100644 --- a/test/functional/fixtures/lsp-test-rpc-server.lua +++ b/test/functional/fixtures/lsp-test-rpc-server.lua @@ -170,7 +170,7 @@ function tests.basic_check_buffer_open() expect_notification('textDocument/didOpen', { textDocument = { languageId = ""; - text = table.concat({"testing"; "123"}, "\n"); + text = table.concat({"testing"; "123"}, "\n") .. '\n'; uri = "file://"; version = 0; }; @@ -197,6 +197,42 @@ function tests.basic_check_buffer_open_and_change() expect_notification('textDocument/didOpen', { textDocument = { languageId = ""; + text = table.concat({"testing"; "123"}, "\n") .. '\n'; + uri = "file://"; + version = 0; + }; + }) + expect_notification('textDocument/didChange', { + textDocument = { + uri = "file://"; + version = 3; + }; + contentChanges = { + { text = table.concat({"testing"; "boop"}, "\n") .. '\n'; }; + } + }) + expect_notification("finish") + notify('finish') + end; + } +end + +function tests.basic_check_buffer_open_and_change_noeol() + skeleton { + on_init = function(params) + local expected_capabilities = protocol.make_client_capabilities() + assert_eq(params.capabilities, expected_capabilities) + return { + capabilities = { + textDocumentSync = protocol.TextDocumentSyncKind.Full; + } + } + end; + body = function() + notify('start') + expect_notification('textDocument/didOpen', { + textDocument = { + languageId = ""; text = table.concat({"testing"; "123"}, "\n"); uri = "file://"; version = 0; @@ -216,7 +252,6 @@ function tests.basic_check_buffer_open_and_change() end; } end - function tests.basic_check_buffer_open_and_change_multi() skeleton { on_init = function(params) @@ -233,7 +268,7 @@ function tests.basic_check_buffer_open_and_change_multi() expect_notification('textDocument/didOpen', { textDocument = { languageId = ""; - text = table.concat({"testing"; "123"}, "\n"); + text = table.concat({"testing"; "123"}, "\n") .. '\n'; uri = "file://"; version = 0; }; @@ -244,7 +279,7 @@ function tests.basic_check_buffer_open_and_change_multi() version = 3; }; contentChanges = { - { text = table.concat({"testing"; "321"}, "\n"); }; + { text = table.concat({"testing"; "321"}, "\n") .. '\n'; }; } }) expect_notification('textDocument/didChange', { @@ -253,7 +288,7 @@ function tests.basic_check_buffer_open_and_change_multi() version = 4; }; contentChanges = { - { text = table.concat({"testing"; "boop"}, "\n"); }; + { text = table.concat({"testing"; "boop"}, "\n") .. '\n'; }; } }) expect_notification("finish") @@ -278,7 +313,7 @@ function tests.basic_check_buffer_open_and_change_multi_and_close() expect_notification('textDocument/didOpen', { textDocument = { languageId = ""; - text = table.concat({"testing"; "123"}, "\n"); + text = table.concat({"testing"; "123"}, "\n") .. '\n'; uri = "file://"; version = 0; }; @@ -289,7 +324,7 @@ function tests.basic_check_buffer_open_and_change_multi_and_close() version = 3; }; contentChanges = { - { text = table.concat({"testing"; "321"}, "\n"); }; + { text = table.concat({"testing"; "321"}, "\n") .. '\n'; }; } }) expect_notification('textDocument/didChange', { @@ -298,7 +333,7 @@ function tests.basic_check_buffer_open_and_change_multi_and_close() version = 4; }; contentChanges = { - { text = table.concat({"testing"; "boop"}, "\n"); }; + { text = table.concat({"testing"; "boop"}, "\n") .. '\n'; }; } }) expect_notification('textDocument/didClose', { @@ -328,7 +363,7 @@ function tests.basic_check_buffer_open_and_change_incremental() expect_notification('textDocument/didOpen', { textDocument = { languageId = ""; - text = table.concat({"testing"; "123"}, "\n"); + text = table.concat({"testing"; "123"}, "\n") .. '\n'; uri = "file://"; version = 0; }; diff --git a/test/functional/plugin/lsp/lsp_spec.lua b/test/functional/plugin/lsp/lsp_spec.lua index cd0974b81c..c38c9b72ce 100644 --- a/test/functional/plugin/lsp/lsp_spec.lua +++ b/test/functional/plugin/lsp/lsp_spec.lua @@ -410,6 +410,54 @@ describe('Language Client API', function() } end) + it('should check the body and didChange full with noeol', function() + local expected_callbacks = { + {NIL, "shutdown", {}, 1}; + {NIL, "finish", {}, 1}; + {NIL, "start", {}, 1}; + } + local client + test_rpc_server { + test_name = "basic_check_buffer_open_and_change_noeol"; + on_setup = function() + exec_lua [[ + BUFFER = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(BUFFER, 0, -1, false, { + "testing"; + "123"; + }) + vim.api.nvim_buf_set_option(BUFFER, 'eol', false) + ]] + end; + on_init = function(_client) + client = _client + local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") + eq(full_kind, client.resolved_capabilities().text_document_did_change) + eq(true, client.resolved_capabilities().text_document_open_close) + exec_lua [[ + assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) + ]] + end; + on_exit = function(code, signal) + eq(0, code, "exit code") eq(0, signal, "exit signal") + end; + on_callback = function(err, method, params, client_id) + if method == 'start' then + exec_lua [[ + vim.api.nvim_buf_set_lines(BUFFER, 1, 2, false, { + "boop"; + }) + ]] + client.notify('finish') + end + eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback") + if method == 'finish' then + client.stop() + end + end; + } + end) + -- TODO(askhan) we don't support full for now, so we can disable these tests. pending('should check the body and didChange incremental', function() local expected_callbacks = { |