mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Add close_language_servers
method on Editor
This commit is contained in:
parent
dd0af78079
commit
c5a2fd5da3
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -342,6 +342,7 @@ version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"crossterm",
|
||||
"futures-util",
|
||||
"helix-core",
|
||||
"helix-lsp",
|
||||
"helix-tui",
|
||||
|
@ -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");
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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(|_| ())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user