on master help sign in
Add `close_language_servers` method on `Editor`
commitc5a2fd5da394b5b16695af9f2eb437e29be010f0 authorwojciechkepka <wojtek.kepka@protonmail.com> dateSat 19 Jun 2021, 05:14 (5 years ago) parentdd0af78
4 files changed+23−10
Cargo.lock+1 helix-term/src/application.rs+1−10 helix-view/Cargo.toml+1 helix-view/src/editor.rs+20
Cargo.lock+1
@@ -342,6 +342,7 @@ version = "0.2.0"
342342dependencies = [
343343 "anyhow",
344344 "crossterm",
345+ "futures-util",
345346 "helix-core",
346347 "helix-lsp",
347348 "helix-tui",
helix-term/src/application.rs+1−10
@@ -406,16 +406,7 @@ impl Application {
406406
407407 self.event_loop().await;
408408
409− tokio::time::timeout(
410− Duration::from_millis(500),
411− future::join_all(
412− self.editor
413− .language_servers
414− .iter_clients()
415− .map(|client| client.force_shutdown()),
416− ),
417− )
418− .await;
409+ self.editor.close_language_servers(None).await;
419410
420411 // reset cursor shape
421412 write!(stdout, "\x1B[2 q");
helix-view/Cargo.toml+1
@@ -27,6 +27,7 @@ once_cell = "1.8"
2727url = "2"
2828
2929tokio = { version = "1", features = ["full"] }
30+futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
3031
3132slotmap = "1"
3233
helix-view/src/editor.rs+20
@@ -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}