mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 13:24:19 +00:00
Fix another place where Copilot may panic
This commit is contained in:
parent
b5a39de3e2
commit
b131a2cb98
1 changed files with 21 additions and 18 deletions
|
@ -8043,24 +8043,27 @@ 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)) => {
|
||||||
let new_server_id = copilot_server.server_id();
|
// Another event wants to re-add the server that was already added and subscribed to, avoid doing it again.
|
||||||
let weak_project = cx.weak_handle();
|
if !copilot_server.has_notification_handler::<copilot::request::LogMessage>() {
|
||||||
let copilot_log_subscription = copilot_server
|
let new_server_id = copilot_server.server_id();
|
||||||
.on_notification::<copilot::request::LogMessage, _>(
|
let weak_project = cx.weak_handle();
|
||||||
move |params, mut cx| {
|
let copilot_log_subscription = copilot_server
|
||||||
if let Some(project) = weak_project.upgrade(&mut cx) {
|
.on_notification::<copilot::request::LogMessage, _>(
|
||||||
project.update(&mut cx, |_, cx| {
|
move |params, mut cx| {
|
||||||
cx.emit(Event::LanguageServerLog(
|
if let Some(project) = weak_project.upgrade(&mut cx) {
|
||||||
new_server_id,
|
project.update(&mut cx, |_, cx| {
|
||||||
params.message,
|
cx.emit(Event::LanguageServerLog(
|
||||||
));
|
new_server_id,
|
||||||
})
|
params.message,
|
||||||
}
|
));
|
||||||
},
|
})
|
||||||
);
|
}
|
||||||
project.supplementary_language_servers.insert(new_server_id, (name.clone(), Arc::clone(copilot_server)));
|
},
|
||||||
project.copilot_log_subscription = Some(copilot_log_subscription);
|
);
|
||||||
cx.emit(Event::LanguageServerAdded(new_server_id));
|
project.supplementary_language_servers.insert(new_server_id, (name.clone(), Arc::clone(copilot_server)));
|
||||||
|
project.copilot_log_subscription = Some(copilot_log_subscription);
|
||||||
|
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"),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue