From 47de4dcd327d3634d44f521ccc59b5ae42a2d8d8 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 3 Apr 2023 21:38:26 -0700 Subject: [PATCH] removed copilot from generated schema and command palette --- Cargo.lock | 1 + crates/copilot/src/copilot.rs | 15 +++++++++++++-- crates/settings/Cargo.toml | 1 + crates/settings/src/settings.rs | 4 ++++ crates/staff_mode/src/staff_mode.rs | 27 ++++++++++++++++++++++++--- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38ba75f343c7e7f0b68b318eec44f9fc7cd91341..b22d1710eb4cf1383e7345bd359a0350ed4e5e50 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 e0215af6226953b90d6e9da00c244f3b073774cf..93ab35533878fda20acc5a12761b89ddf90c0150 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 59728083966898da1f0be4e966b9de0df00ca7ca..fbb3ad63f34761a0f7004a818582569c87dbd7ad 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 0988b2d6d9c86b1374042bd4d3639c9594de1523..feb4017018098ffd7040e3ec2c1416b055658c8f 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 30f061466f8b256bb0adcc2f00385eb6e2a3648b..bf5c0e9caf289ec8ccc633cbf0e1bf5f5d568250 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 {}