diff --git a/.gitignore b/.gitignore index 6a6fc782a827..aab4c97d8225 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target helix-term/rustfmt.toml result runtime/grammars +.DS_Store \ No newline at end of file diff --git a/book/src/configuration.md b/book/src/configuration.md index 0890d28328ca..d138d92dd386 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -117,6 +117,7 @@ The following statusline elements can be configured: | `display-messages` | Display LSP progress messages below statusline[^1] | `false` | | `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` | | `display-signature-help-docs` | Display docs under signature help popup | `true` | +| `shutdown-timeout` | Time in milliseconds to wait for lsp to shutdown before closing editor, set to 0 to close instantly. | `3000` | [^1]: By default, a progress spinner is shown in the statusline beside the file path. diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 7a50e007b9b9..23045950b62b 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -1087,7 +1087,8 @@ impl Application { errs.push(err); } - if self.editor.close_language_servers(None).await.is_err() { + let timeout = self.editor.config().lsp.shutdown_timeout; + if self.editor.close_language_servers(timeout).await.is_err() && !timeout.is_zero() { log::error!("Timed out waiting for language servers to shutdown"); errs.push(anyhow::format_err!( "Timed out waiting for language servers to shutdown" diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c13a66736948..c0627a85c4c0 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -242,6 +242,13 @@ pub struct LspConfig { pub auto_signature_help: bool, /// Display docs under signature help popup pub display_signature_help_docs: bool, + /// Time in milliseconds that the editor will wait for the lsp to shutdown before exiting + /// Set to 0 for instant. Defaults to 3000. + #[serde( + serialize_with = "serialize_duration_millis", + deserialize_with = "deserialize_duration_millis" + )] + pub shutdown_timeout: Duration, } impl Default for LspConfig { @@ -250,6 +257,7 @@ impl Default for LspConfig { display_messages: false, auto_signature_help: true, display_signature_help_docs: true, + shutdown_timeout: Duration::from_millis(3000), } } } @@ -1356,14 +1364,13 @@ impl Editor { } } - /// Closes language servers with timeout. The default timeout is 10000 ms, use - /// `timeout` parameter to override this. + /// Closes language servers with timeout, set to 0 to instantly shutdown without waiting for lsp pub async fn close_language_servers( &self, - timeout: Option, + timeout: Duration, ) -> Result<(), tokio::time::error::Elapsed> { tokio::time::timeout( - Duration::from_millis(timeout.unwrap_or(3000)), + timeout, future::join_all( self.language_servers .iter_clients()