@@ -2,7 +2,9 @@ use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, V
22use tui::layout::Rect;
33use tui::terminal::CursorKind;
44
5+use futures_util::future;
56use std::path::PathBuf;
7+use std::time::Duration;
68
79use slotmap::SlotMap;
810
@@ -270,4 +272,22 @@ impl Editor {
270272 (None, CursorKind::Hidden)
271273 }
272274 }
275+
276+ /// Closes language servers with timeout. The default timeout is 500 ms, use
277+ /// `timeout` parameter to override this.
278+ pub async fn close_language_servers(
279+ &self,
280+ timeout: Option<u64>,
281+ ) -> Result<(), tokio::time::error::Elapsed> {
282+ tokio::time::timeout(
283+ Duration::from_millis(timeout.unwrap_or(500)),
284+ future::join_all(
285+ self.language_servers
286+ .iter_clients()
287+ .map(|client| client.force_shutdown()),
288+ ),
289+ )
290+ .await
291+ .map(|_| ())
292+ }
273293}