diff --git a/crates/edit_prediction/src/mercury.rs b/crates/edit_prediction/src/mercury.rs index ac9f8f535572dddb56ffcfde9a5f2040a65cf168..b47bd2ad0374eba33e7b8db726c2fa13c0519465 100644 --- a/crates/edit_prediction/src/mercury.rs +++ b/crates/edit_prediction/src/mercury.rs @@ -309,3 +309,9 @@ pub fn mercury_api_token(cx: &mut App) -> Entity { }) .clone() } + +pub fn load_mercury_api_token(cx: &mut App) -> Task> { + mercury_api_token(cx).update(cx, |key_state, cx| { + key_state.load_if_needed(MERCURY_CREDENTIALS_URL, |s| s, cx) + }) +} diff --git a/crates/edit_prediction/src/sweep_ai.rs b/crates/edit_prediction/src/sweep_ai.rs index 7d020c219b47aa8bcf6fb89e516b7f8ff93da497..2ed24cd8ef728383ec800acbb2ab7c7b99f07c06 100644 --- a/crates/edit_prediction/src/sweep_ai.rs +++ b/crates/edit_prediction/src/sweep_ai.rs @@ -282,6 +282,12 @@ pub fn sweep_api_token(cx: &mut App) -> Entity { .clone() } +pub fn load_sweep_api_token(cx: &mut App) -> Task> { + sweep_api_token(cx).update(cx, |key_state, cx| { + key_state.load_if_needed(SWEEP_CREDENTIALS_URL, |s| s, cx) + }) +} + #[derive(Debug, Clone, Serialize)] struct AutocompleteRequest { pub debug_info: Arc, diff --git a/crates/edit_prediction_ui/src/edit_prediction_button.rs b/crates/edit_prediction_ui/src/edit_prediction_button.rs index bbf9f4677df278c014379964e7bdc714e6ce78d8..0dcea477200eef9d1eeb6adeff98f47332d751ca 100644 --- a/crates/edit_prediction_ui/src/edit_prediction_button.rs +++ b/crates/edit_prediction_ui/src/edit_prediction_button.rs @@ -487,6 +487,21 @@ impl EditPredictionButton { cx.observe_global::(move |_, cx| cx.notify()) .detach(); + cx.observe_global::(move |_, cx| cx.notify()) + .detach(); + + let sweep_api_token_task = edit_prediction::sweep_ai::load_sweep_api_token(cx); + let mercury_api_token_task = edit_prediction::mercury::load_mercury_api_token(cx); + + cx.spawn(async move |this, cx| { + _ = futures::join!(sweep_api_token_task, mercury_api_token_task); + this.update(cx, |_, cx| { + cx.notify(); + }) + .ok(); + }) + .detach(); + CodestralEditPredictionDelegate::ensure_api_key_loaded(client.http_client(), cx); Self { @@ -503,7 +518,7 @@ impl EditPredictionButton { } } - fn get_available_providers(&self, cx: &App) -> Vec { + fn get_available_providers(&self, cx: &mut App) -> Vec { let mut providers = Vec::new(); providers.push(EditPredictionProvider::Zed); @@ -532,12 +547,10 @@ impl EditPredictionButton { providers.push(EditPredictionProvider::Codestral); } - let ep_store = EditPredictionStore::try_global(cx); - if cx.has_flag::() - && ep_store - .as_ref() - .is_some_and(|ep_store| ep_store.read(cx).has_sweep_api_token(cx)) + && edit_prediction::sweep_ai::sweep_api_token(cx) + .read(cx) + .has_key() { providers.push(EditPredictionProvider::Experimental( EXPERIMENTAL_SWEEP_EDIT_PREDICTION_PROVIDER_NAME, @@ -545,9 +558,9 @@ impl EditPredictionButton { } if cx.has_flag::() - && ep_store - .as_ref() - .is_some_and(|ep_store| ep_store.read(cx).has_mercury_api_token(cx)) + && edit_prediction::mercury::mercury_api_token(cx) + .read(cx) + .has_key() { providers.push(EditPredictionProvider::Experimental( EXPERIMENTAL_MERCURY_EDIT_PREDICTION_PROVIDER_NAME,