diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-10-21 09:36:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-21 09:36:01 -0700 |
commit | 80456cf83676c0f06dd084faede3a43d0831cf78 (patch) | |
tree | 41d22dc73622cccb964af68f23fba27afdda6715 /runtime/lua/vim/lsp.lua | |
parent | eaa03b7181ff0e0cca7aef263206035c66e34302 (diff) | |
download | rneovim-80456cf83676c0f06dd084faede3a43d0831cf78.tar.gz rneovim-80456cf83676c0f06dd084faede3a43d0831cf78.tar.bz2 rneovim-80456cf83676c0f06dd084faede3a43d0831cf78.zip |
feat(lsp): add exit_timeout flag (#16070)
* This flag allows customizing the time before sending kill -15 to the
server. If set to false, neovim exits immediately after sending
request('shutdown'). Otherwise, polls until all servers have shutdown,
and then kills remaining servers via kill -15 at exit_timeout
duration. Defaults to 500 ms.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 9a008ac965..56ac1cbc66 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -644,7 +644,9 @@ end --- - debounce_text_changes (number, default nil): Debounce didChange --- notifications to the server by the given number in milliseconds. No debounce --- occurs if nil ---- +--- - exit_timeout (number, default 500): Milliseconds to wait for server to +-- exit cleanly after sending the 'shutdown' request before sending kill -15. +-- If set to false, nvim exits immediately after sending the 'shutdown' request to the server. ---@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be --- fully initialized. Use `on_init` to do any actions once --- the client has been initialized. @@ -1226,9 +1228,38 @@ function lsp._vim_exit_handler() client.stop() end - if not vim.wait(500, function() return tbl_isempty(active_clients) end, 50) then - for _, client in pairs(active_clients) do - client.stop(true) + local timeouts = {} + local max_timeout = 0 + local send_kill = false + + for client_id, client in pairs(active_clients) do + local timeout = if_nil(client.config.flags.exit_timeout, 500) + if timeout then + send_kill = true + timeouts[client_id] = timeout + max_timeout = math.max(timeout, max_timeout) + else + active_clients[client_id] = nil + end + end + + local poll_time = 50 + + local function check_clients_closed() + for client_id, _ in pairs(active_clients) do + timeouts[client_id] = timeouts[client_id] - poll_time + if timeouts[client_id] < 0 then + active_clients[client_id] = nil + end + end + return tbl_isempty(active_clients) + end + + if send_kill then + if not vim.wait(max_timeout, check_clients_closed, poll_time) then + for _, client in pairs(active_clients) do + client.stop(true) + end end end end |