aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
diff options
context:
space:
mode:
authorjdrouhard <john@jmdtech.org>2021-10-29 07:45:01 -0500
committerGitHub <noreply@github.com>2021-10-29 05:45:01 -0700
commitd1c470957b49380ec5ceba603dbd85a14f60f09b (patch)
tree89b2453ed810b27ee86c9f0d8c7f4efb0e60f098 /runtime/lua/vim/lsp.lua
parent1dbbaf89bf5d3bcd1edac3af9938c2e2dd18f816 (diff)
downloadrneovim-d1c470957b49380ec5ceba603dbd85a14f60f09b.tar.gz
rneovim-d1c470957b49380ec5ceba603dbd85a14f60f09b.tar.bz2
rneovim-d1c470957b49380ec5ceba603dbd85a14f60f09b.zip
feat(lsp): track pending+cancel requests on client object #15949
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r--runtime/lua/vim/lsp.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 56ac1cbc66..3a067373d0 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -772,8 +772,10 @@ function lsp.start_client(config)
attached_buffers = {};
handlers = handlers;
+ requests = {};
+
-- for $/progress report
- messages = { name = name, messages = {}, progress = {}, status = {} }
+ messages = { name = name, messages = {}, progress = {}, status = {} };
}
-- Store the uninitialized_clients for cleanup in case we exit before initialize finishes.
@@ -906,11 +908,21 @@ function lsp.start_client(config)
end
-- Ensure pending didChange notifications are sent so that the server doesn't operate on a stale state
changetracking.flush(client)
-
+ bufnr = resolve_bufnr(bufnr)
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, handler, bufnr)
- return rpc.request(method, params, function(err, result)
+ local success, request_id = rpc.request(method, params, function(err, result)
handler(err, result, {method=method, client_id=client_id, bufnr=bufnr, params=params})
+ end, function(request_id)
+ client.requests[request_id] = nil
+ nvim_command("doautocmd <nomodeline> User LspRequest")
end)
+
+ if success then
+ client.requests[request_id] = { type='pending', bufnr=bufnr, method=method }
+ nvim_command("doautocmd <nomodeline> User LspRequest")
+ end
+
+ return success, request_id
end
---@private
@@ -970,6 +982,11 @@ function lsp.start_client(config)
---@see |vim.lsp.client.notify()|
function client.cancel_request(id)
validate{id = {id, 'n'}}
+ local request = client.requests[id]
+ if request and request.type == 'pending' then
+ request.type = 'cancel'
+ nvim_command("doautocmd <nomodeline> User LspRequest")
+ end
return rpc.notify("$/cancelRequest", { id = id })
end