diff --git a/Cargo.lock b/Cargo.lock index 8fd76300f7507a284375e12e1275724972bebe7f..f38ea8f740e87643b063ecc358899e6ba0b0fd10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5295,6 +5295,7 @@ dependencies = [ "url", "util", "uuid", + "vim_mode_setting", "workspace", "workspace-hack", "zed_actions", diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index be06cc04dfc7ee3f080e8d995783abb819e95842..52b3fa2affeca1ceb87485fb1242fe40b34f8f57 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -89,6 +89,7 @@ ui.workspace = true url.workspace = true util.workspace = true uuid.workspace = true +vim_mode_setting.workspace = true workspace.workspace = true zed_actions.workspace = true workspace-hack.workspace = true diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index d8501f2104a00183be68dc461f9128a600227aa6..4084f61bb4a44d591aa544a622fa8888f56a5c57 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -21678,12 +21678,10 @@ impl Editor { } } -// todo(settings_refactor) this should not be! fn vim_enabled(cx: &App) -> bool { - cx.global::() - .raw_user_settings() - .and_then(|settings| settings.content.vim_mode) - == Some(true) + vim_mode_setting::VimModeSetting::try_get(cx) + .map(|vim_mode| vim_mode.0) + .unwrap_or(false) } fn process_completion_for_edit( diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index c95c20a3352bb067e492874f6f650d38f04671b2..369d445b2051f463e862483f4afd1b8c444bb9ea 100644 --- a/crates/project/src/project_settings.rs +++ b/crates/project/src/project_settings.rs @@ -770,12 +770,9 @@ impl SettingsObserver { envelope: TypedEnvelope, cx: AsyncApp, ) -> anyhow::Result<()> { - let new_settings = serde_json::from_str(&envelope.payload.contents).with_context(|| { - format!("deserializing {} user settings", envelope.payload.contents) - })?; cx.update_global(|settings_store: &mut SettingsStore, cx| { settings_store - .set_raw_user_settings(new_settings, cx) + .set_user_settings(&envelope.payload.contents, cx) .context("setting new user settings")?; anyhow::Ok(()) })??; diff --git a/crates/remote_server/src/remote_editing_tests.rs b/crates/remote_server/src/remote_editing_tests.rs index cb486732c0a0a63e7f6d5d5aed7fe0499ef98b80..16b6e49063ad091967d88943024167bb246f8e2c 100644 --- a/crates/remote_server/src/remote_editing_tests.rs +++ b/crates/remote_server/src/remote_editing_tests.rs @@ -1797,8 +1797,8 @@ async fn test_remote_external_agent_server( pretty_assertions::assert_eq!(names, ["gemini", "claude"]); server_cx.update_global::(|settings_store, cx| { settings_store - .set_raw_server_settings( - Some(json!({ + .set_server_settings( + &json!({ "agent_servers": { "foo": { "command": "foo-cli", @@ -1808,7 +1808,8 @@ async fn test_remote_external_agent_server( } } } - })), + }) + .to_string(), cx, ) .unwrap(); diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index 43402cae0e6c723b4cc2e94f28c1ba7d0c61c928..38bff4d6a1428f017bcd65be3d27e945aebccabd 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -166,13 +166,6 @@ impl SettingsContent { } } -#[skip_serializing_none] -#[derive(Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)] -pub struct ServerSettingsContent { - #[serde(flatten)] - pub project: ProjectSettingsContent, -} - #[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct UserSettingsContent { diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index dc703e50f1de43aee8059e144dc4cb0815b3472d..a575182a4144d99bf3c3c7f29f649735ea8b8891 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -36,8 +36,7 @@ use crate::{ merge_from::MergeFrom, parse_json_with_comments, replace_value_in_json_text, settings_content::{ - ExtensionsSettingsContent, ProjectSettingsContent, ServerSettingsContent, SettingsContent, - UserSettingsContent, + ExtensionsSettingsContent, ProjectSettingsContent, SettingsContent, UserSettingsContent, }, update_value_in_json_text, }; @@ -327,33 +326,6 @@ impl SettingsStore { self.user_settings.as_ref() } - /// Replaces current settings with the values from the given JSON. - pub fn set_raw_user_settings( - &mut self, - new_settings: UserSettingsContent, - cx: &mut App, - ) -> Result<()> { - self.user_settings = Some(new_settings); - self.recompute_values(None, cx)?; - Ok(()) - } - - /// Replaces current settings with the values from the given JSON. - pub fn set_raw_server_settings( - &mut self, - new_settings: Option, - cx: &mut App, - ) -> Result<()> { - // Rewrite the server settings into a content type - self.server_settings = new_settings - .map(|settings| settings.to_string()) - .and_then(|str| parse_json_with_comments::(&str).ok()) - .map(Box::new); - - self.recompute_values(None, cx)?; - Ok(()) - } - /// Get the configured settings profile names. pub fn configured_settings_profiles(&self) -> impl Iterator { self.user_settings @@ -361,11 +333,6 @@ impl SettingsStore { .flat_map(|settings| settings.profiles.keys().map(|k| k.as_str())) } - /// Access the raw JSON value of the default settings. - pub fn raw_default_settings(&self) -> &SettingsContent { - &self.default_settings - } - #[cfg(any(test, feature = "test-support"))] pub fn test(cx: &mut App) -> Self { Self::new(cx, &crate::test_settings()) @@ -621,19 +588,14 @@ impl SettingsStore { server_settings_content: &str, cx: &mut App, ) -> Result<()> { - let settings: Option = if server_settings_content.is_empty() { + let settings: Option = if server_settings_content.is_empty() { None } else { parse_json_with_comments(server_settings_content)? }; // Rewrite the server settings into a content type - self.server_settings = settings.map(|settings| { - Box::new(SettingsContent { - project: settings.project, - ..Default::default() - }) - }); + self.server_settings = settings.map(|settings| Box::new(settings)); self.recompute_values(None, cx)?; Ok(())