Add close_language_servers
method on Editor
This commit is contained in:
parent
dd0af78079
commit
c5a2fd5da3
4 changed files with 23 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -342,6 +342,7 @@ version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
"futures-util",
|
||||||
"helix-core",
|
"helix-core",
|
||||||
"helix-lsp",
|
"helix-lsp",
|
||||||
"helix-tui",
|
"helix-tui",
|
||||||
|
|
|
@ -406,16 +406,7 @@ impl Application {
|
||||||
|
|
||||||
self.event_loop().await;
|
self.event_loop().await;
|
||||||
|
|
||||||
tokio::time::timeout(
|
self.editor.close_language_servers(None).await;
|
||||||
Duration::from_millis(500),
|
|
||||||
future::join_all(
|
|
||||||
self.editor
|
|
||||||
.language_servers
|
|
||||||
.iter_clients()
|
|
||||||
.map(|client| client.force_shutdown()),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// reset cursor shape
|
// reset cursor shape
|
||||||
write!(stdout, "\x1B[2 q");
|
write!(stdout, "\x1B[2 q");
|
||||||
|
|
|
@ -27,6 +27,7 @@ once_cell = "1.8"
|
||||||
url = "2"
|
url = "2"
|
||||||
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
|
||||||
|
|
||||||
slotmap = "1"
|
slotmap = "1"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, V
|
||||||
use tui::layout::Rect;
|
use tui::layout::Rect;
|
||||||
use tui::terminal::CursorKind;
|
use tui::terminal::CursorKind;
|
||||||
|
|
||||||
|
use futures_util::future;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use slotmap::SlotMap;
|
use slotmap::SlotMap;
|
||||||
|
|
||||||
|
@ -270,4 +272,22 @@ impl Editor {
|
||||||
(None, CursorKind::Hidden)
|
(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(|_| ())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue