aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRishikesh Vaishnav <rishhvaishnav@gmail.com>2021-10-08 11:19:33 -0700
committerGitHub <noreply@github.com>2021-10-08 11:19:33 -0700
commit3f097321955e32b0724e0f0d059ecef3d764aac8 (patch)
tree94cd9ed952679735ecde9d4021234ca6a55e6a65
parent5cbd0fba00ecc07099b6af919fed5f403a0ed1cb (diff)
downloadrneovim-3f097321955e32b0724e0f0d059ecef3d764aac8.tar.gz
rneovim-3f097321955e32b0724e0f0d059ecef3d764aac8.tar.bz2
rneovim-3f097321955e32b0724e0f0d059ecef3d764aac8.zip
fix(lsp): expose ContentModified error code to callbacks (#15262)
-rw-r--r--runtime/lua/vim/lsp/rpc.lua5
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua29
-rw-r--r--test/functional/plugin/lsp_spec.lua48
3 files changed, 78 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index b1bdb24def..d9a684a738 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -466,15 +466,12 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
-- We sent a number, so we expect a number.
local result_id = tonumber(decoded.id)
- -- Do not surface RequestCancelled or ContentModified to users, it is RPC-internal.
+ -- Do not surface RequestCancelled to users, it is RPC-internal.
if decoded.error then
local mute_error = false
if decoded.error.code == protocol.ErrorCodes.RequestCancelled then
local _ = log.debug() and log.debug("Received cancellation ack", decoded)
mute_error = true
- elseif decoded.error.code == protocol.ErrorCodes.ContentModified then
- local _ = log.debug() and log.debug("Received content modified ack", decoded)
- mute_error = true
end
if mute_error then
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index 8e03d9a46e..c102a98002 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -246,6 +246,35 @@ function tests.capabilities_for_client_supports_method()
}
end
+function tests.check_forward_request_cancelled()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ expect_request("error_code_test", function()
+ return {code = -32800}, nil
+ end)
+ notify('finish')
+ end;
+ }
+end
+
+function tests.check_forward_content_modified()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ expect_request("error_code_test", function()
+ return {code = -32801}, nil
+ end)
+ expect_notification('finish')
+ notify('finish')
+ end;
+ }
+end
+
function tests.basic_finish()
skeleton {
on_init = function(params)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 8f9b194690..f5c02afeaa 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -480,6 +480,54 @@ describe('LSP', function()
}
end)
+ it('should not forward RequestCancelled to callback', function()
+ local expected_handlers = {
+ {NIL, "finish", {}, 1};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_forward_request_cancelled";
+ on_init = function(_client)
+ _client.request("error_code_test")
+ client = _client
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, method, ...)
+ eq(table.remove(expected_handlers), {err, method, ...}, "expected handler")
+ if method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
+ it('should forward ContentModified to callback', function()
+ local expected_handlers = {
+ {NIL, "finish", {}, 1};
+ {{code = -32801}, "error_code_test", NIL, 1, NIL};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_forward_content_modified";
+ on_init = function(_client)
+ _client.request("error_code_test")
+ client = _client
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, method, ...)
+ eq(table.remove(expected_handlers), {err, method, ...}, "expected handler")
+ if method == 'error_code_test' then client.notify("finish") end
+ if method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
it('should not send didOpen if the buffer closes before init', function()
local expected_handlers = {
{NIL, {}, {method="shutdown", client_id=1}};