Reland "Remove cx from ThemeSettings" (#39720)

- **Reapply "Remove cx from ThemeSettings (#38836)" (#39691)**
- **Fix theme loading races**

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin
2025-10-08 17:36:52 +02:00
committed by GitHub
parent 70af11ef2a
commit 1d1c799b4b
60 changed files with 395 additions and 462 deletions
+1 -2
View File
@@ -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()
}
+25 -30
View File
@@ -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));
}
@@ -948,7 +944,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);
}
}
@@ -985,8 +981,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);
}
}
@@ -1070,8 +1065,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 {
@@ -1142,7 +1137,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(),
}
@@ -1156,7 +1151,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(),
@@ -1185,7 +1180,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(),
@@ -1209,9 +1204,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),
@@ -1317,7 +1312,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),
@@ -1525,9 +1520,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(
@@ -1646,7 +1641,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
@@ -1695,7 +1690,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)
@@ -1752,8 +1747,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());
@@ -1881,7 +1876,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());