Created
May 23, 2021 00:29
-
-
Save Thiago4532/ad3067c9c5f306e1c7af7f1b13a99c13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2e6c09838f88803f31d229002715628639631897 Mon Sep 17 00:00:00 2001 | |
From: Brian Shu <[email protected]> | |
Date: Wed, 17 Mar 2021 17:44:18 -0400 | |
Subject: [PATCH] lsp: fix blocking in closing of clients | |
--- | |
runtime/lua/vim/lsp.lua | 33 ++++++++++++++++++++++++++++++--- | |
1 file changed, 30 insertions(+), 3 deletions(-) | |
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua | |
index a6f118abdec9..1db9fd43acb0 100644 | |
--- a/runtime/lua/vim/lsp.lua | |
+++ b/runtime/lua/vim/lsp.lua | |
@@ -1057,11 +1057,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 function wait_async(timeout, ms, predicate, cb) | |
+ local timer = uv.new_timer() | |
+ local time = 0 | |
+ | |
+ local function done(in_time) | |
+ timer:stop() | |
+ timer:close() | |
+ cb(in_time) | |
end | |
+ | |
+ timer:start(0, ms, function() | |
+ if predicate() == true then | |
+ done(true) | |
+ return | |
+ end | |
+ | |
+ if time == timeout then | |
+ done(false) | |
+ return | |
+ end | |
+ | |
+ time = time + ms | |
+ end) | |
end | |
+ | |
+ wait_async(500, 50, function() return tbl_isempty(active_clients) end, function(in_time) | |
+ if not in_time then | |
+ for _, client in pairs(active_clients) do | |
+ client.stop(true) | |
+ end | |
+ end | |
+ end) | |
end | |
nvim_command("autocmd VimLeavePre * lua vim.lsp._vim_exit_handler()") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment