Handle language server shutdown with timeout
This commit is contained in:
parent
03d1ca7b0a
commit
c2aad859b1
3 changed files with 31 additions and 1 deletions
|
@ -272,6 +272,21 @@ impl Client {
|
||||||
self.notify::<lsp::notification::Exit>(())
|
self.notify::<lsp::notification::Exit>(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tries to shut down the language server but returns
|
||||||
|
/// early if server responds with an error.
|
||||||
|
pub async fn shutdown_and_exit(&self) -> Result<()> {
|
||||||
|
self.shutdown().await?;
|
||||||
|
self.exit().await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Forcefully shuts down the language server ignoring any errors.
|
||||||
|
pub async fn force_shutdown(&self) -> Result<()> {
|
||||||
|
if let Err(e) = self.shutdown().await {
|
||||||
|
log::warn!("language server failed to terminate gracefully - {}", e);
|
||||||
|
}
|
||||||
|
self.exit().await
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
// Text document
|
// Text document
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -310,6 +310,10 @@ impl Registry {
|
||||||
Err(Error::LspNotDefined)
|
Err(Error::LspNotDefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn iter_clients(&self) -> impl Iterator<Item = &Arc<Client>> {
|
||||||
|
self.inner.values().map(|(_, client)| client)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -23,7 +23,7 @@ use crossterm::{
|
||||||
|
|
||||||
use tui::layout::Rect;
|
use tui::layout::Rect;
|
||||||
|
|
||||||
use futures_util::stream::FuturesUnordered;
|
use futures_util::{future, stream::FuturesUnordered};
|
||||||
|
|
||||||
type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
|
type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
|
||||||
pub type LspCallback =
|
pub type LspCallback =
|
||||||
|
@ -406,6 +406,17 @@ impl Application {
|
||||||
|
|
||||||
self.event_loop().await;
|
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;
|
||||||
|
|
||||||
// reset cursor shape
|
// reset cursor shape
|
||||||
write!(stdout, "\x1B[2 q");
|
write!(stdout, "\x1B[2 q");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue