Skip to content

Commit

Permalink
Add close_language_servers method on Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k authored and archseer committed Jun 19, 2021
1 parent dd0af78 commit c5a2fd5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,7 @@ impl Application {

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");
Expand Down
1 change: 1 addition & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
20 changes: 20 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, V
use tui::layout::Rect;
use tui::terminal::CursorKind;

use futures_util::future;
use std::path::PathBuf;
use std::time::Duration;

use slotmap::SlotMap;

Expand Down Expand Up @@ -270,4 +272,22 @@ impl Editor {
(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(|_| ())
}
}

0 comments on commit c5a2fd5

Please sign in to comment.