Merge pull request #11433 from bfredl/lspeol

lsp: transmit "\n" after last line when 'eol' is set
This commit is contained in:
Björn Linse 2019-11-21 12:45:52 +01:00 committed by GitHub
commit cc5487e32f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 13 deletions

View File

@ -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)

View File

@ -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,7 +197,7 @@ function tests.basic_check_buffer_open_and_change()
expect_notification('textDocument/didOpen', {
textDocument = {
languageId = "";
text = table.concat({"testing"; "123"}, "\n");
text = table.concat({"testing"; "123"}, "\n") .. '\n';
uri = "file://";
version = 0;
};
@ -208,7 +208,7 @@ function tests.basic_check_buffer_open_and_change()
version = 3;
};
contentChanges = {
{ text = table.concat({"testing"; "boop"}, "\n"); };
{ text = table.concat({"testing"; "boop"}, "\n") .. '\n'; };
}
})
expect_notification("finish")
@ -217,7 +217,7 @@ function tests.basic_check_buffer_open_and_change()
}
end
function tests.basic_check_buffer_open_and_change_multi()
function tests.basic_check_buffer_open_and_change_noeol()
skeleton {
on_init = function(params)
local expected_capabilities = protocol.make_client_capabilities()
@ -244,7 +244,42 @@ function tests.basic_check_buffer_open_and_change_multi()
version = 3;
};
contentChanges = {
{ text = table.concat({"testing"; "321"}, "\n"); };
{ text = table.concat({"testing"; "boop"}, "\n"); };
}
})
expect_notification("finish")
notify('finish')
end;
}
end
function tests.basic_check_buffer_open_and_change_multi()
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") .. '\n';
uri = "file://";
version = 0;
};
})
expect_notification('textDocument/didChange', {
textDocument = {
uri = "file://";
version = 3;
};
contentChanges = {
{ 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;
};

View File

@ -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 = {