diff options
author | Brian Shu <littlebubu.shu@gmail.com> | 2021-03-17 17:44:18 -0400 |
---|---|---|
committer | Brian Shu <littlebubu.shu@gmail.com> | 2021-04-19 20:04:08 -0400 |
commit | 2e6c09838f88803f31d229002715628639631897 (patch) | |
tree | 82fdbb762efde1103dc322b343b99005e7441dc2 /runtime/lua/vim/lsp.lua | |
parent | 4d1fc167a8a14067a848719a1d6c772edce6e11f (diff) | |
download | rneovim-2e6c09838f88803f31d229002715628639631897.tar.gz rneovim-2e6c09838f88803f31d229002715628639631897.tar.bz2 rneovim-2e6c09838f88803f31d229002715628639631897.zip |
lsp: fix blocking in closing of clients
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index a6f118abde..1db9fd43ac 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()") |