Do not resubscribe for Copilot logs events (#3014)

Last follow-up of https://github.com/zed-industries/zed/pull/3002
Fixes
https://zed-industries.slack.com/archives/C04S6T1T7TQ/p1695281196667609

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.

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2023-09-22 13:48:13 +03:00 committed by GitHub
commit 1f1c669673
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -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::<lsp::notification::LogMessage>() {
// 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| {

View file

@ -605,6 +605,10 @@ impl LanguageServer {
self.notification_handlers.lock().remove(T::METHOD);
}
pub fn has_notification_handler<T: notification::Notification>(&self) -> bool {
self.notification_handlers.lock().contains_key(T::METHOD)
}
#[must_use]
pub fn on_custom_notification<Params, F>(&self, method: &'static str, mut f: F) -> Subscription
where