aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorwojciechkepka2021-06-19 03:14:40 +0000
committerBlaž Hrastnik2021-06-19 04:02:56 +0000
commitc5a2fd5da394b5b16695af9f2eb437e29be010f0 (patch)
treee7614ad9152ad7e29b8b882352559d1a410f7928 /helix-view
parentdd0af78079342b46ae1f4d1b265c7e0cd7519631 (diff)
Add `close_language_servers` method on `Editor`
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/Cargo.toml1
-rw-r--r--helix-view/src/editor.rs20
2 files changed, 21 insertions, 0 deletions
diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml
index 13539a5a..7f18e9a2 100644
--- a/helix-view/Cargo.toml
+++ b/helix-view/Cargo.toml
@@ -27,6 +27,7 @@ once_cell = "1.8"
url = "2"
tokio = { version = "1", features = ["full"] }
+futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
slotmap = "1"
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<u64>,
+ ) -> 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(|_| ())
+ }
}