Add close_language_servers method on Editor

This commit is contained in:
wojciechkepka 2021-06-19 05:14:40 +02:00 committed by Blaž Hrastnik
parent dd0af78079
commit c5a2fd5da3
4 changed files with 23 additions and 10 deletions

1
Cargo.lock generated
View File

@ -342,6 +342,7 @@ version = "0.2.0"
dependencies = [
"anyhow",
"crossterm",
"futures-util",
"helix-core",
"helix-lsp",
"helix-tui",

View File

@ -406,16 +406,7 @@ pub async fn run(&mut self) -> Result<(), Error> {
self.event_loop().await;
tokio::time::timeout(
Duration::from_millis(500),
future::join_all(
self.editor
.language_servers
.iter_clients()
.map(|client| client.force_shutdown()),
),
)
.await;
self.editor.close_language_servers(None).await;
// reset cursor shape
write!(stdout, "\x1B[2 q");

View File

@ -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"

View File

@ -2,7 +2,9 @@
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 @@ pub fn cursor(&self) -> (Option<Position>, CursorKind) {
(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(|_| ())
}
}