From c5a2fd5da394b5b16695af9f2eb437e29be010f0 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sat, 19 Jun 2021 05:14:40 +0200 Subject: Add `close_language_servers` method on `Editor` --- helix-view/src/editor.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'helix-view/src') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index a1c93f75..db8ae87a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -2,7 +2,9 @@ use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, V use tui::layout::Rect; use tui::terminal::CursorKind; +use futures_util::future; use std::path::PathBuf; +use std::time::Duration; use slotmap::SlotMap; @@ -270,4 +272,22 @@ impl Editor { (None, CursorKind::Hidden) } } + + /// Closes language servers with timeout. The default timeout is 500 ms, use + /// `timeout` parameter to override this. + pub async fn close_language_servers( + &self, + timeout: Option, + ) -> Result<(), tokio::time::error::Elapsed> { + tokio::time::timeout( + Duration::from_millis(timeout.unwrap_or(500)), + future::join_all( + self.language_servers + .iter_clients() + .map(|client| client.force_shutdown()), + ), + ) + .await + .map(|_| ()) + } } -- cgit v1.2.3-70-g09d2