Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

edit_prediction: Skip cloud Zeta requests when not signed in (#57615)

Seth Wood46845bf2f5a4
diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rs
index f310e9865e3..53bd4bfbbcf 100644
--- a/crates/edit_prediction/src/edit_prediction.rs
+++ b/crates/edit_prediction/src/edit_prediction.rs
@@ -2550,6 +2550,15 @@ impl EditPredictionStore {
allow_jump: bool,
cx: &mut Context<Self>,
) -> Task<Result<Option<EditPredictionResult>>> {
+ let is_cloud_zeta = matches!(self.edit_prediction_model, EditPredictionModel::Zeta)
+ && !matches!(
+ all_language_settings(None, cx).edit_predictions.provider,
+ EditPredictionProvider::Ollama | EditPredictionProvider::OpenAiCompatibleApi
+ );
+ if is_cloud_zeta && !self.client.cloud_client().has_credentials() {
+ return Task::ready(Ok(None));
+ }
+
self.get_or_init_project(&project, cx);
let project_state = self.projects.get(&project.entity_id()).unwrap();
let stored_events = project_state.events(cx);
diff --git a/crates/edit_prediction/src/edit_prediction_tests.rs b/crates/edit_prediction/src/edit_prediction_tests.rs
index fb348616ba6..52c6948cdc5 100644
--- a/crates/edit_prediction/src/edit_prediction_tests.rs
+++ b/crates/edit_prediction/src/edit_prediction_tests.rs
@@ -3204,11 +3204,18 @@ async fn test_unauthenticated_without_custom_url_blocks_prediction_impl(cx: &mut
let project = Project::test(fs.clone(), [path!("/project").as_ref()], cx).await;
- let http_client = FakeHttpClient::create(|_req| async move {
- Ok(gpui::http_client::Response::builder()
- .status(401)
- .body("Unauthorized".into())
- .unwrap())
+ let request_count = Arc::new(std::sync::atomic::AtomicUsize::default());
+ let http_client = FakeHttpClient::create({
+ let request_count = request_count.clone();
+ move |_req| {
+ request_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ async move {
+ Ok(gpui::http_client::Response::builder()
+ .status(401)
+ .body("Unauthorized".into())
+ .unwrap())
+ }
+ }
});
let client =
@@ -3241,11 +3248,8 @@ async fn test_unauthenticated_without_custom_url_blocks_prediction_impl(cx: &mut
ep_store.request_prediction(&project, &buffer, cursor, Default::default(), cx)
});
- let result = completion_task.await;
- assert!(
- result.is_err(),
- "Without authentication and without custom URL, prediction should fail"
- );
+ assert!(completion_task.await.unwrap().is_none());
+ assert_eq!(request_count.load(std::sync::atomic::Ordering::SeqCst), 0);
}
#[gpui::test]