diff --git a/crates/edit_prediction/src/edit_prediction.rs b/crates/edit_prediction/src/edit_prediction.rs index 13d7aa1d294c3acbcd69d1d4c211c49d23ed0b80..bb2e7154d2ec5334d597df592a1ce8f8a19d8068 100644 --- a/crates/edit_prediction/src/edit_prediction.rs +++ b/crates/edit_prediction/src/edit_prediction.rs @@ -1642,7 +1642,7 @@ impl EditPredictionStore { let can_collect_example = snapshot .file() .is_some_and(|file| self.can_collect_file(&project, file, cx)) - && self.can_collect_events(&inputs.events); + && self.can_collect_events(&inputs.events, cx); if can_collect_example && should_sample_edit_prediction_example_capture(cx) { let events_for_capture = @@ -2010,11 +2010,11 @@ impl EditPredictionStore { } fn can_collect_file(&self, project: &Entity, file: &Arc, cx: &App) -> bool { - self.data_collection_choice.is_enabled() && self.is_file_open_source(project, file, cx) + self.data_collection_choice.is_enabled(cx) && self.is_file_open_source(project, file, cx) } - fn can_collect_events(&self, events: &[Arc]) -> bool { - if !self.data_collection_choice.is_enabled() { + fn can_collect_events(&self, events: &[Arc], cx: &App) -> bool { + if !self.data_collection_choice.is_enabled(cx) { return false; } events.iter().all(|event| { @@ -2048,10 +2048,11 @@ impl EditPredictionStore { fn toggle_data_collection_choice(&mut self, cx: &mut Context) { self.data_collection_choice = self.data_collection_choice.toggle(); let new_choice = self.data_collection_choice; + let is_enabled = new_choice.is_enabled(cx); db::write_and_log(cx, move || { KEY_VALUE_STORE.write_kvp( ZED_PREDICT_DATA_COLLECTION_CHOICE.into(), - new_choice.is_enabled().to_string(), + is_enabled.to_string(), ) }); } @@ -2139,20 +2140,16 @@ pub enum DataCollectionChoice { } impl DataCollectionChoice { - pub fn is_enabled(self) -> bool { + pub fn is_enabled(self, cx: &App) -> bool { + if cx.is_staff() { + return true; + } match self { Self::Enabled => true, Self::NotAnswered | Self::Disabled => false, } } - pub fn is_answered(self) -> bool { - match self { - Self::Enabled | Self::Disabled => true, - Self::NotAnswered => false, - } - } - #[must_use] pub fn toggle(&self) -> DataCollectionChoice { match self { diff --git a/crates/edit_prediction/src/zed_edit_prediction_delegate.rs b/crates/edit_prediction/src/zed_edit_prediction_delegate.rs index 289bcd76daab2b9a4b82db88b86285e6c7aca00d..fa2f210ac0c1f009791329db02cee1ad61cbe226 100644 --- a/crates/edit_prediction/src/zed_edit_prediction_delegate.rs +++ b/crates/edit_prediction/src/zed_edit_prediction_delegate.rs @@ -66,7 +66,7 @@ impl EditPredictionDelegate for ZedEditPredictionDelegate { self.store .read(cx) .is_file_open_source(&self.project, file, cx); - if self.store.read(cx).data_collection_choice.is_enabled() { + if self.store.read(cx).data_collection_choice.is_enabled(cx) { DataCollectionState::Enabled { is_project_open_source, } diff --git a/crates/edit_prediction/src/zeta1.rs b/crates/edit_prediction/src/zeta1.rs index 01c26573307e66cd6ca3bf8ab748ba8d082ea688..d4ee8f661ba05a5dd09628250e1df59f8895203c 100644 --- a/crates/edit_prediction/src/zeta1.rs +++ b/crates/edit_prediction/src/zeta1.rs @@ -103,7 +103,7 @@ pub(crate) fn request_prediction_with_zeta1( let included_events = &events[events.len() - included_events_count..events.len()]; body.can_collect_data = can_collect_file && this - .read_with(cx, |this, _| this.can_collect_events(included_events)) + .read_with(cx, |this, cx| this.can_collect_events(included_events, cx)) .unwrap_or(false); if body.can_collect_data { body.git_info = git_info; diff --git a/crates/edit_prediction_ui/src/edit_prediction_button.rs b/crates/edit_prediction_ui/src/edit_prediction_button.rs index f6a6cf958e2e57aaec4618578c85d8da95632592..031e915a10fbe45781700c62364b220ae720e05b 100644 --- a/crates/edit_prediction_ui/src/edit_prediction_button.rs +++ b/crates/edit_prediction_ui/src/edit_prediction_button.rs @@ -778,6 +778,7 @@ impl EditPredictionButton { .toggleable(IconPosition::Start, data_collection.is_enabled()) .icon(icon_name) .icon_color(icon_color) + .disabled(cx.is_staff()) .documentation_aside(DocumentationSide::Left, move |cx| { let (msg, label_color, icon_name, icon_color) = match (is_open_source, is_collecting) { (true, true) => (