Fix another place where Copilot may panic

This commit is contained in:
Kirill Bulatov 2023-09-26 10:51:13 +03:00
parent b5a39de3e2
commit b131a2cb98

View file

@ -8043,6 +8043,8 @@ fn subscribe_for_copilot_events(
copilot::Event::CopilotLanguageServerStarted => { copilot::Event::CopilotLanguageServerStarted => {
match copilot.read(cx).language_server() { match copilot.read(cx).language_server() {
Some((name, copilot_server)) => { Some((name, copilot_server)) => {
// Another event wants to re-add the server that was already added and subscribed to, avoid doing it again.
if !copilot_server.has_notification_handler::<copilot::request::LogMessage>() {
let new_server_id = copilot_server.server_id(); let new_server_id = copilot_server.server_id();
let weak_project = cx.weak_handle(); let weak_project = cx.weak_handle();
let copilot_log_subscription = copilot_server let copilot_log_subscription = copilot_server
@ -8062,6 +8064,7 @@ fn subscribe_for_copilot_events(
project.copilot_log_subscription = Some(copilot_log_subscription); project.copilot_log_subscription = Some(copilot_log_subscription);
cx.emit(Event::LanguageServerAdded(new_server_id)); cx.emit(Event::LanguageServerAdded(new_server_id));
} }
}
None => debug_panic!("Received Copilot language server started event, but no language server is running"), None => debug_panic!("Received Copilot language server started event, but no language server is running"),
} }
} }