diff --git a/Cargo.lock b/Cargo.lock index 38ba75f343..b22d1710eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5952,6 +5952,7 @@ dependencies = [ "serde_json", "serde_path_to_error", "sqlez", + "staff_mode", "theme", "toml", "tree-sitter", diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index e0215af622..93ab355338 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -18,7 +18,7 @@ use node_runtime::NodeRuntime; use request::{LogMessage, StatusNotification}; use settings::Settings; use smol::{fs, io::BufReader, stream::StreamExt}; -use staff_mode::staff_mode; +use staff_mode::{not_staff_mode, staff_mode}; use std::{ ffi::OsString, @@ -37,8 +37,13 @@ const COPILOT_NAMESPACE: &'static str = "copilot"; actions!(copilot, [NextSuggestion, PreviousSuggestion, Reinstall]); pub fn init(client: Arc, node_runtime: Arc, cx: &mut MutableAppContext) { - staff_mode(cx, { + staff_mode::(cx, { move |cx| { + cx.update_global::(|filter, _cx| { + filter.filtered_namespaces.remove(COPILOT_NAMESPACE); + filter.filtered_namespaces.remove(COPILOT_AUTH_NAMESPACE); + }); + let copilot = cx.add_model({ let node_runtime = node_runtime.clone(); let http = client.http_client().clone(); @@ -51,6 +56,12 @@ pub fn init(client: Arc, node_runtime: Arc, cx: &mut Mutabl sign_in::init(cx); } }); + not_staff_mode::(cx, |cx| { + cx.update_global::(|filter, _cx| { + filter.filtered_namespaces.insert(COPILOT_NAMESPACE); + filter.filtered_namespaces.insert(COPILOT_AUTH_NAMESPACE); + }); + }); cx.add_global_action(|_: &SignIn, cx| { if let Some(copilot) = Copilot::global(cx) { diff --git a/crates/settings/Cargo.toml b/crates/settings/Cargo.toml index 5972808396..fbb3ad63f3 100644 --- a/crates/settings/Cargo.toml +++ b/crates/settings/Cargo.toml @@ -20,6 +20,7 @@ fs = { path = "../fs" } anyhow = "1.0.38" futures = "0.3" theme = { path = "../theme" } +staff_mode = { path = "../staff_mode" } util = { path = "../util" } json_comments = "0.2" postage = { workspace = true } diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 0988b2d6d9..feb4017018 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -177,6 +177,7 @@ pub struct EditorSettings { pub ensure_final_newline_on_save: Option, pub formatter: Option, pub enable_language_server: Option, + #[schemars(skip)] pub copilot: Option, } @@ -436,6 +437,7 @@ pub struct SettingsFileContent { #[serde(default)] pub base_keymap: Option, #[serde(default)] + #[schemars(skip)] pub enable_copilot_integration: Option, } @@ -779,6 +781,7 @@ pub fn settings_file_json_schema( settings.option_add_null_type = false; }); let generator = SchemaGenerator::new(settings); + let mut root_schema = generator.into_root_schema_for::(); // Create a schema for a theme name. @@ -791,6 +794,7 @@ pub fn settings_file_json_schema( // Create a schema for a 'languages overrides' object, associating editor // settings with specific langauges. assert!(root_schema.definitions.contains_key("EditorSettings")); + let languages_object_schema = SchemaObject { instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))), object: Some(Box::new(ObjectValidation { diff --git a/crates/staff_mode/src/staff_mode.rs b/crates/staff_mode/src/staff_mode.rs index 30f061466f..bf5c0e9caf 100644 --- a/crates/staff_mode/src/staff_mode.rs +++ b/crates/staff_mode/src/staff_mode.rs @@ -11,12 +11,13 @@ impl std::ops::Deref for StaffMode { } } -/// Despite what the type system requires me to tell you, the init function will only ever be called once -pub fn staff_mode( +/// Despite what the type system requires me to tell you, the init function will only be called a once +/// as soon as we know that the staff mode is enabled. +pub fn staff_mode( cx: &mut MutableAppContext, mut init: F, ) { - if **cx.default_global::() { + if !S::staff_only() || **cx.default_global::() { init(cx) } else { let mut once = Some(()); @@ -28,3 +29,23 @@ pub fn staff_mode( .detach(); } } + +/// Immediately checks and runs the init function if the staff mode is not enabled. +pub fn not_staff_mode( + cx: &mut MutableAppContext, + init: F, +) { + if !S::staff_only() || !**cx.default_global::() { + init(cx) + } +} + +pub trait StaffModeConfiguration { + fn staff_only() -> bool { + true + } +} + +pub enum Copilot {} + +impl StaffModeConfiguration for Copilot {}