From 571609fb8960755a6f0f9416ef0a28acc52830c0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 25 Dec 2021 10:10:18 -0500 Subject: [PATCH] fix(lsp): call config on_exit handler before context is cleared (#16781) The on_exit handler provided to the client configuration is called after the client's context is cleared (e.g. which buffers the client was attached to). Calling the handler sooner allows these handlers to access the client object and do their own cleanup with the full context. (cherry picked from commit 5ab49430ee0601335f195feb8592844d04851604) Co-authored-by: Gregory Anders --- runtime/lua/vim/lsp.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 69d8fd0b42..42953cbfee 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -776,6 +776,10 @@ function lsp.start_client(config) ---@param code (number) exit code of the process ---@param signal (number) the signal used to terminate (if any) function dispatch.on_exit(code, signal) + if config.on_exit then + pcall(config.on_exit, code, signal, client_id) + end + active_clients[client_id] = nil uninitialized_clients[client_id] = nil @@ -791,10 +795,6 @@ function lsp.start_client(config) vim.notify(msg, vim.log.levels.WARN) end) end - - if config.on_exit then - pcall(config.on_exit, code, signal, client_id) - end end -- Start the RPC client.