From e96f639b608a596aa1ea8abb7e5b799cedbb0b1a Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 5 Dec 2022 18:32:32 +0800 Subject: fix: restart client after client is stopped after LspRestart (#2290) * fix: restart client after client is stopped after LspRestart * fix: format --- plugin/lspconfig.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'plugin/lspconfig.lua') diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index 0877cbd7..5526264c 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -87,12 +87,28 @@ end, { }) api.nvim_create_user_command('LspRestart', function(info) + local detach_clients = {} for _, client in ipairs(get_clients_from_cmd_args(info.args)) do client.stop() - vim.defer_fn(function() - require('lspconfig.configs')[client.name].launch() - end, 500) + detach_clients[client.name] = client end + local timer = vim.loop.new_timer() + timer:start( + 500, + 100, + vim.schedule_wrap(function() + for client_name, client in pairs(detach_clients) do + if client.is_stopped() then + require('lspconfig.configs')[client_name].launch() + detach_clients[client_name] = nil + end + end + + if next(detach_clients) == nil and not timer:is_closing() then + timer:close() + end + end) + ) end, { desc = 'Manually restart the given language client(s)', nargs = '?', -- cgit v1.2.3-70-g09d2