on master help sign in
Add `close_language_servers` method on `Editor`
c5a2fd5wojciechkepka
Cargo.lock+1
@@ -342,6 +342,7 @@ version = "0.2.0"
342dependencies = [
342dependencies = [
343 "anyhow",
343 "anyhow",
344 "crossterm",
344 "crossterm",
345+ "futures-util",
345 "helix-core",
346 "helix-core",
346 "helix-lsp",
347 "helix-lsp",
347 "helix-tui",
348 "helix-tui",
helix-term/src/application.rs+1−10
@@ -406,16 +406,7 @@ impl Application {
406
406
407 self.event_loop().await;
407 self.event_loop().await;
408
408
409− tokio::time::timeout(
409+ self.editor.close_language_servers(None).await;
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;
419
410
420 // reset cursor shape
411 // reset cursor shape
421 write!(stdout, "\x1B[2 q");
412 write!(stdout, "\x1B[2 q");
helix-view/Cargo.toml+1
@@ -27,6 +27,7 @@ once_cell = "1.8"
27url = "2"
27url = "2"
28
28
29tokio = { version = "1", features = ["full"] }
29tokio = { version = "1", features = ["full"] }
30+futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
30
31
31slotmap = "1"
32slotmap = "1"
32
33
helix-view/src/editor.rs+20
@@ -2,7 +2,9 @@ use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, V
2use tui::layout::Rect;
2use tui::layout::Rect;
3use tui::terminal::CursorKind;
3use tui::terminal::CursorKind;
4
4
5+use futures_util::future;
5use std::path::PathBuf;
6use std::path::PathBuf;
7+use std::time::Duration;
6
8
7use slotmap::SlotMap;
9use slotmap::SlotMap;
8
10
@@ -270,4 +272,22 @@ impl Editor {
270 (None, CursorKind::Hidden)
272 (None, CursorKind::Hidden)
271 }
273 }
272 }
274 }
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+ }
273}
293}