Remove cx from ThemeSettings (#38836)
Before this change the active theme and icon theme were retrofitted onto the ThemeSettings. Now they're in their own new global (GlobalTheme::theme(cx) and GlobalTheme::icon_theme(cx)) This lets us remove cx from the settings traits, and tidy up a few other things along the way. Release Notes: - N/A
This commit is contained in:
@@ -4,7 +4,6 @@ use crate::{
|
||||
self as settings,
|
||||
settings_content::{BaseKeymapContent, SettingsContent},
|
||||
};
|
||||
use gpui::App;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, VsCodeSettings};
|
||||
@@ -131,7 +130,7 @@ impl BaseKeymap {
|
||||
}
|
||||
|
||||
impl Settings for BaseKeymap {
|
||||
fn from_settings(s: &crate::settings_content::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(s: &crate::settings_content::SettingsContent) -> Self {
|
||||
s.base_keymap.unwrap().into()
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,7 @@ pub trait Settings: 'static + Send + Sync + Sized {
|
||||
///
|
||||
/// This function *should* panic if default values are missing,
|
||||
/// and you should add a default to default.json for documentation.
|
||||
fn from_settings(content: &SettingsContent, cx: &mut App) -> Self;
|
||||
|
||||
fn missing_default() -> anyhow::Error {
|
||||
anyhow::anyhow!("missing default for: {}", std::any::type_name::<Self>())
|
||||
}
|
||||
fn from_settings(content: &SettingsContent) -> Self;
|
||||
|
||||
/// Use [the helpers in the vscode_import module](crate::vscode_import) to apply known
|
||||
/// equivalent settings from a vscode config to our config
|
||||
@@ -82,8 +78,8 @@ pub trait Settings: 'static + Send + Sync + Sized {
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store.register_setting::<Self>(cx);
|
||||
SettingsStore::update_global(cx, |store, _| {
|
||||
store.register_setting::<Self>();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,7 +201,7 @@ struct SettingValue<T> {
|
||||
trait AnySettingValue: 'static + Send + Sync {
|
||||
fn setting_type_name(&self) -> &'static str;
|
||||
|
||||
fn from_settings(&self, s: &SettingsContent, cx: &mut App) -> Box<dyn Any>;
|
||||
fn from_settings(&self, s: &SettingsContent) -> Box<dyn Any>;
|
||||
|
||||
fn value_for_path(&self, path: Option<SettingsLocation>) -> &dyn Any;
|
||||
fn all_local_values(&self) -> Vec<(WorktreeId, Arc<RelPath>, &dyn Any)>;
|
||||
@@ -259,7 +255,7 @@ impl SettingsStore {
|
||||
}
|
||||
|
||||
/// Add a new type of setting to the store.
|
||||
pub fn register_setting<T: Settings>(&mut self, cx: &mut App) {
|
||||
pub fn register_setting<T: Settings>(&mut self) {
|
||||
let setting_type_id = TypeId::of::<T>();
|
||||
let entry = self.setting_values.entry(setting_type_id);
|
||||
|
||||
@@ -271,7 +267,7 @@ impl SettingsStore {
|
||||
global_value: None,
|
||||
local_values: Vec::new(),
|
||||
}));
|
||||
let value = T::from_settings(&self.merged_settings, cx);
|
||||
let value = T::from_settings(&self.merged_settings);
|
||||
setting_value.set_global_value(Box::new(value));
|
||||
}
|
||||
|
||||
@@ -944,7 +940,7 @@ impl SettingsStore {
|
||||
self.merged_settings = Rc::new(merged);
|
||||
|
||||
for setting_value in self.setting_values.values_mut() {
|
||||
let value = setting_value.from_settings(&self.merged_settings, cx);
|
||||
let value = setting_value.from_settings(&self.merged_settings);
|
||||
setting_value.set_global_value(value);
|
||||
}
|
||||
}
|
||||
@@ -981,8 +977,7 @@ impl SettingsStore {
|
||||
}
|
||||
|
||||
for setting_value in self.setting_values.values_mut() {
|
||||
let value =
|
||||
setting_value.from_settings(&project_settings_stack.last().unwrap(), cx);
|
||||
let value = setting_value.from_settings(&project_settings_stack.last().unwrap());
|
||||
setting_value.set_local_value(*root_id, directory_path.clone(), value);
|
||||
}
|
||||
}
|
||||
@@ -1066,8 +1061,8 @@ impl Debug for SettingsStore {
|
||||
}
|
||||
|
||||
impl<T: Settings> AnySettingValue for SettingValue<T> {
|
||||
fn from_settings(&self, s: &SettingsContent, cx: &mut App) -> Box<dyn Any> {
|
||||
Box::new(T::from_settings(s, cx)) as _
|
||||
fn from_settings(&self, s: &SettingsContent) -> Box<dyn Any> {
|
||||
Box::new(T::from_settings(s)) as _
|
||||
}
|
||||
|
||||
fn setting_type_name(&self) -> &'static str {
|
||||
@@ -1138,7 +1133,7 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Settings for AutoUpdateSetting {
|
||||
fn from_settings(content: &SettingsContent, _: &mut App) -> Self {
|
||||
fn from_settings(content: &SettingsContent) -> Self {
|
||||
AutoUpdateSetting {
|
||||
auto_update: content.auto_update.unwrap(),
|
||||
}
|
||||
@@ -1152,7 +1147,7 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Settings for ItemSettings {
|
||||
fn from_settings(content: &SettingsContent, _: &mut App) -> Self {
|
||||
fn from_settings(content: &SettingsContent) -> Self {
|
||||
let content = content.tabs.clone().unwrap();
|
||||
ItemSettings {
|
||||
close_position: content.close_position.unwrap(),
|
||||
@@ -1181,7 +1176,7 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Settings for DefaultLanguageSettings {
|
||||
fn from_settings(content: &SettingsContent, _: &mut App) -> Self {
|
||||
fn from_settings(content: &SettingsContent) -> Self {
|
||||
let content = &content.project.all_languages.defaults;
|
||||
DefaultLanguageSettings {
|
||||
tab_size: content.tab_size.unwrap(),
|
||||
@@ -1205,9 +1200,9 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn test_settings_store_basic(cx: &mut App) {
|
||||
let mut store = SettingsStore::new(cx, &default_settings());
|
||||
store.register_setting::<AutoUpdateSetting>(cx);
|
||||
store.register_setting::<ItemSettings>(cx);
|
||||
store.register_setting::<DefaultLanguageSettings>(cx);
|
||||
store.register_setting::<AutoUpdateSetting>();
|
||||
store.register_setting::<ItemSettings>();
|
||||
store.register_setting::<DefaultLanguageSettings>();
|
||||
|
||||
assert_eq!(
|
||||
store.get::<AutoUpdateSetting>(None),
|
||||
@@ -1313,7 +1308,7 @@ mod tests {
|
||||
store
|
||||
.set_user_settings(r#"{ "auto_update": false }"#, cx)
|
||||
.unwrap();
|
||||
store.register_setting::<AutoUpdateSetting>(cx);
|
||||
store.register_setting::<AutoUpdateSetting>();
|
||||
|
||||
assert_eq!(
|
||||
store.get::<AutoUpdateSetting>(None),
|
||||
@@ -1521,9 +1516,9 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn test_vscode_import(cx: &mut App) {
|
||||
let mut store = SettingsStore::new(cx, &test_settings());
|
||||
store.register_setting::<DefaultLanguageSettings>(cx);
|
||||
store.register_setting::<ItemSettings>(cx);
|
||||
store.register_setting::<AutoUpdateSetting>(cx);
|
||||
store.register_setting::<DefaultLanguageSettings>();
|
||||
store.register_setting::<ItemSettings>();
|
||||
store.register_setting::<AutoUpdateSetting>();
|
||||
|
||||
// create settings that werent present
|
||||
check_vscode_import(
|
||||
@@ -1642,7 +1637,7 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn test_global_settings(cx: &mut App) {
|
||||
let mut store = SettingsStore::new(cx, &test_settings());
|
||||
store.register_setting::<ItemSettings>(cx);
|
||||
store.register_setting::<ItemSettings>();
|
||||
|
||||
// Set global settings - these should override defaults but not user settings
|
||||
store
|
||||
@@ -1691,7 +1686,7 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn test_get_value_for_field_basic(cx: &mut App) {
|
||||
let mut store = SettingsStore::new(cx, &test_settings());
|
||||
store.register_setting::<DefaultLanguageSettings>(cx);
|
||||
store.register_setting::<DefaultLanguageSettings>();
|
||||
|
||||
store
|
||||
.set_user_settings(r#"{"preferred_line_length": 0}"#, cx)
|
||||
@@ -1748,8 +1743,8 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn test_get_value_for_field_local_worktrees_dont_interfere(cx: &mut App) {
|
||||
let mut store = SettingsStore::new(cx, &test_settings());
|
||||
store.register_setting::<DefaultLanguageSettings>(cx);
|
||||
store.register_setting::<AutoUpdateSetting>(cx);
|
||||
store.register_setting::<DefaultLanguageSettings>();
|
||||
store.register_setting::<AutoUpdateSetting>();
|
||||
|
||||
let local_1 = (WorktreeId::from_usize(0), RelPath::empty().into_arc());
|
||||
|
||||
@@ -1877,7 +1872,7 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn test_get_overrides_for_field(cx: &mut App) {
|
||||
let mut store = SettingsStore::new(cx, &test_settings());
|
||||
store.register_setting::<DefaultLanguageSettings>(cx);
|
||||
store.register_setting::<DefaultLanguageSettings>();
|
||||
|
||||
let wt0_root = (WorktreeId::from_usize(0), RelPath::empty().into_arc());
|
||||
let wt0_child1 = (WorktreeId::from_usize(0), rel_path("child1").into_arc());
|
||||
|
||||
Reference in New Issue
Block a user