Skip to content

Commit

Permalink
Cleanup clients after event loop, not on drop
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Jun 18, 2021
1 parent 1a326cb commit 55d728f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 0 additions & 7 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use jsonrpc_core as jsonrpc;
use lsp_types as lsp;
use serde_json::Value;
use std::future::Future;
use std::ops::Drop;
use std::process::Stdio;
use std::sync::atomic::{AtomicU64, Ordering};
use tokio::{
Expand All @@ -26,12 +25,6 @@ pub struct Client {
offset_encoding: OffsetEncoding,
}

impl Drop for Client {
fn drop(&mut self) {
let _ = crate::block_on(self.force_shutdown());
}
}

impl Client {
pub fn start(cmd: &str, args: &[String]) -> Result<(Self, UnboundedReceiver<Call>)> {
let process = Command::new(cmd)
Expand Down
4 changes: 4 additions & 0 deletions helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ impl Registry {
Err(Error::LspNotDefined)
}
}

pub fn iter_clients(&self) -> impl Iterator<Item = &Arc<Client>> {
self.inner.values()
}
}

// REGISTRY = HashMap<LanguageId, Lazy/OnceCell<Arc<RwLock<Client>>>
Expand Down
11 changes: 10 additions & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crossterm::{

use tui::layout::Rect;

use futures_util::stream::FuturesUnordered;
use futures_util::{future, stream::FuturesUnordered};

use std::pin::Pin;

type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
Expand Down Expand Up @@ -331,6 +332,14 @@ impl Application {

self.event_loop().await;

future::join_all(
self.editor
.language_servers
.iter_clients()
.map(|client| client.force_shutdown()),
)
.await;

// reset cursor shape
write!(stdout, "\x1B[2 q");

Expand Down

0 comments on commit 55d728f

Please sign in to comment.