removed copilot from generated schema and command palette

This commit is contained in:
Mikayla Maki 2023-04-03 21:38:26 -07:00
parent 6bfecd7f66
commit 47de4dcd32
5 changed files with 43 additions and 5 deletions

1
Cargo.lock generated
View file

@ -5952,6 +5952,7 @@ dependencies = [
"serde_json",
"serde_path_to_error",
"sqlez",
"staff_mode",
"theme",
"toml",
"tree-sitter",

View file

@ -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<Client>, node_runtime: Arc<NodeRuntime>, cx: &mut MutableAppContext) {
staff_mode(cx, {
staff_mode::<staff_mode::Copilot, _>(cx, {
move |cx| {
cx.update_global::<collections::CommandPaletteFilter, _, _>(|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<Client>, node_runtime: Arc<NodeRuntime>, cx: &mut Mutabl
sign_in::init(cx);
}
});
not_staff_mode::<staff_mode::Copilot, _>(cx, |cx| {
cx.update_global::<collections::CommandPaletteFilter, _, _>(|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) {

View file

@ -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 }

View file

@ -177,6 +177,7 @@ pub struct EditorSettings {
pub ensure_final_newline_on_save: Option<bool>,
pub formatter: Option<Formatter>,
pub enable_language_server: Option<bool>,
#[schemars(skip)]
pub copilot: Option<OnOff>,
}
@ -436,6 +437,7 @@ pub struct SettingsFileContent {
#[serde(default)]
pub base_keymap: Option<BaseKeymap>,
#[serde(default)]
#[schemars(skip)]
pub enable_copilot_integration: Option<bool>,
}
@ -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::<SettingsFileContent>();
// 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 {

View file

@ -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<F: FnMut(&mut MutableAppContext) + 'static>(
/// 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<S: StaffModeConfiguration, F: FnMut(&mut MutableAppContext) + 'static>(
cx: &mut MutableAppContext,
mut init: F,
) {
if **cx.default_global::<StaffMode>() {
if !S::staff_only() || **cx.default_global::<StaffMode>() {
init(cx)
} else {
let mut once = Some(());
@ -28,3 +29,23 @@ pub fn staff_mode<F: FnMut(&mut MutableAppContext) + 'static>(
.detach();
}
}
/// Immediately checks and runs the init function if the staff mode is not enabled.
pub fn not_staff_mode<S: StaffModeConfiguration, F: FnOnce(&mut MutableAppContext) + 'static>(
cx: &mut MutableAppContext,
init: F,
) {
if !S::staff_only() || !**cx.default_global::<StaffMode>() {
init(cx)
}
}
pub trait StaffModeConfiguration {
fn staff_only() -> bool {
true
}
}
pub enum Copilot {}
impl StaffModeConfiguration for Copilot {}