From d61565d227460742b6c2b8d45b8d079506a0bb35 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 22 Sep 2023 13:40:20 +0300 Subject: [PATCH] Do not resubscribe for Copilot logs events Copilot sends multiple events about its LSP server readiness, not necessarily recreating the server from scratch (e.g. due to re-sign in action). Avoid re-adding same log subscriptions on the same LSP server, which causes panics. --- crates/language_tools/src/lsp_log.rs | 7 +++++++ crates/lsp/src/lsp.rs | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/crates/language_tools/src/lsp_log.rs b/crates/language_tools/src/lsp_log.rs index d0e9e93839..3f29d6f79b 100644 --- a/crates/language_tools/src/lsp_log.rs +++ b/crates/language_tools/src/lsp_log.rs @@ -181,6 +181,13 @@ impl LogStore { }); let server = project.read(cx).language_server_for_id(id); + if let Some(server) = server.as_deref() { + if server.has_notification_handler::() { + // Another event wants to re-add the server that was already added and subscribed to, avoid doing it again. + return Some(server_state.log_buffer.clone()); + } + } + let weak_project = project.downgrade(); let io_tx = self.io_tx.clone(); server_state._io_logs_subscription = server.as_ref().map(|server| { diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index dcfce4f1fb..9b0d6c98b0 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -605,6 +605,10 @@ impl LanguageServer { self.notification_handlers.lock().remove(T::METHOD); } + pub fn has_notification_handler(&self) -> bool { + self.notification_handlers.lock().contains_key(T::METHOD) + } + #[must_use] pub fn on_custom_notification(&self, method: &'static str, mut f: F) -> Subscription where