Skip to content

Commit

Permalink
fix(lsp): call config on_exit handler before context is cleared (neov…
Browse files Browse the repository at this point in the history
…im#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 5ab4943)

Co-authored-by: Gregory Anders <[email protected]>
  • Loading branch information
github-actions[bot] and gpanders authored Dec 25, 2021
1 parent 37a00be commit 571609f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions runtime/lua/vim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down

0 comments on commit 571609f

Please sign in to comment.