From 55d728fd3d4aa3b476475b23329a58c7c02a37e3 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Fri, 18 Jun 2021 06:19:10 +0200 Subject: [PATCH] Cleanup clients after event loop, not on drop --- helix-lsp/src/client.rs | 7 ------- helix-lsp/src/lib.rs | 4 ++++ helix-term/src/application.rs | 11 ++++++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 2809257c32129..c1cfd281d80cc 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -8,7 +8,6 @@ use jsonrpc_core as jsonrpc; use lsp_types as lsp; use serde_json::Value; use std::future::Future; -use std::ops::Drop; use std::process::Stdio; use std::sync::atomic::{AtomicU64, Ordering}; use tokio::{ @@ -26,12 +25,6 @@ pub struct Client { offset_encoding: OffsetEncoding, } -impl Drop for Client { - fn drop(&mut self) { - let _ = crate::block_on(self.force_shutdown()); - } -} - impl Client { pub fn start(cmd: &str, args: &[String]) -> Result<(Self, UnboundedReceiver)> { let process = Command::new(cmd) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index cff6249288031..0d10a98d4ddf1 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -273,6 +273,10 @@ impl Registry { Err(Error::LspNotDefined) } } + + pub fn iter_clients(&self) -> impl Iterator> { + self.inner.values() + } } // REGISTRY = HashMap>> diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index f5cba365155f8..a486683c4d49d 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -22,7 +22,8 @@ use crossterm::{ use tui::layout::Rect; -use futures_util::stream::FuturesUnordered; +use futures_util::{future, stream::FuturesUnordered}; + use std::pin::Pin; type BoxFuture = Pin + Send>>; @@ -331,6 +332,14 @@ impl Application { self.event_loop().await; + future::join_all( + self.editor + .language_servers + .iter_clients() + .map(|client| client.force_shutdown()), + ) + .await; + // reset cursor shape write!(stdout, "\x1B[2 q");