diff --git a/assets/default-settings.json b/assets/default-settings.json index d9c9580242..45032b4288 100644 --- a/assets/default-settings.json +++ b/assets/default-settings.json @@ -2,17 +2,17 @@ "theme": "cave-dark", "buffer_font_family": "Zed Mono", "buffer_font_size": 15, - "hover_popover_enabled": true, "vim_mode": false, - "autosave": "off", + "hover_popover_enabled": true, "projects_online_by_default": true, "enable_language_server": true, + "autosave": "off", "format_on_save": "language_server", "preferred_line_length": 80, "soft_wrap": "none", "hard_tabs": false, "tab_size": 4, - "languages_overrides": { + "languages": { "Plain Text": { "soft_wrap": "preferred_line_length" }, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a4f166b956..4d77dc113d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6236,7 +6236,7 @@ mod tests { use language::{FakeLspAdapter, LanguageConfig}; use lsp::FakeLanguageServer; use project::FakeFs; - use settings::LanguageSettings; + use settings::EditorSettings; use std::{cell::RefCell, rc::Rc, time::Instant}; use text::Point; use unindent::Unindent; @@ -7696,14 +7696,14 @@ mod tests { Settings::test(cx) .with_language_defaults( "TOML", - LanguageSettings { + EditorSettings { tab_size: Some(2.try_into().unwrap()), ..Default::default() }, ) .with_language_defaults( "Rust", - LanguageSettings { + EditorSettings { tab_size: Some(4.try_into().unwrap()), ..Default::default() }, @@ -9380,7 +9380,7 @@ mod tests { cx.update_global::(|settings, _| { settings.language_overrides.insert( "Rust".into(), - LanguageSettings { + EditorSettings { tab_size: Some(8.try_into().unwrap()), ..Default::default() }, @@ -9496,7 +9496,7 @@ mod tests { cx.update_global::(|settings, _| { settings.language_overrides.insert( "Rust".into(), - LanguageSettings { + EditorSettings { tab_size: Some(8.try_into().unwrap()), ..Default::default() }, diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index 6f863ee8c9..1080daff1d 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -883,7 +883,7 @@ async fn test_toggling_enable_language_server( cx.update_global(|settings: &mut Settings, _| { settings.language_overrides.insert( Arc::from("Rust"), - settings::LanguageSettings { + settings::EditorSettings { enable_language_server: Some(false), ..Default::default() }, @@ -900,14 +900,14 @@ async fn test_toggling_enable_language_server( cx.update_global(|settings: &mut Settings, _| { settings.language_overrides.insert( Arc::from("Rust"), - settings::LanguageSettings { + settings::EditorSettings { enable_language_server: Some(true), ..Default::default() }, ); settings.language_overrides.insert( Arc::from("JavaScript"), - settings::LanguageSettings { + settings::EditorSettings { enable_language_server: Some(false), ..Default::default() }, diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 028abbca45..f787b9a516 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -14,7 +14,7 @@ use schemars::{ }; use serde::{de::DeserializeOwned, Deserialize}; use serde_json::Value; -use std::{collections::HashMap, num::NonZeroU32, sync::Arc}; +use std::{collections::HashMap, num::NonZeroU32, str, sync::Arc}; use theme::{Theme, ThemeRegistry}; use util::ResultExt as _; @@ -29,15 +29,15 @@ pub struct Settings { pub hover_popover_enabled: bool, pub vim_mode: bool, pub autosave: Autosave, - pub editor_defaults: LanguageSettings, - pub editor_overrides: LanguageSettings, - pub language_defaults: HashMap, LanguageSettings>, - pub language_overrides: HashMap, LanguageSettings>, + pub editor_defaults: EditorSettings, + pub editor_overrides: EditorSettings, + pub language_defaults: HashMap, EditorSettings>, + pub language_overrides: HashMap, EditorSettings>, pub theme: Arc, } #[derive(Clone, Debug, Default, Deserialize, JsonSchema)] -pub struct LanguageSettings { +pub struct EditorSettings { pub tab_size: Option, pub hard_tabs: Option, pub soft_wrap: Option, @@ -89,9 +89,10 @@ pub struct SettingsFileContent { #[serde(default)] pub autosave: Option, #[serde(flatten)] - pub editor: LanguageSettings, + pub editor: EditorSettings, #[serde(default)] - pub language_overrides: HashMap, LanguageSettings>, + #[serde(alias = "language_overrides")] + pub languages: HashMap, EditorSettings>, #[serde(default)] pub theme: Option, } @@ -107,8 +108,10 @@ impl Settings { value } - let defaults: SettingsFileContent = - serde_json::from_slice(assets.load("default-settings.json").unwrap().as_ref()).unwrap(); + let defaults: SettingsFileContent = parse_json_with_comments( + str::from_utf8(assets.load("default-settings.json").unwrap().as_ref()).unwrap(), + ) + .unwrap(); Self { buffer_font_family: font_cache @@ -120,7 +123,7 @@ impl Settings { projects_online_by_default: defaults.projects_online_by_default.unwrap(), vim_mode: defaults.vim_mode.unwrap(), autosave: defaults.autosave.unwrap(), - editor_defaults: LanguageSettings { + editor_defaults: EditorSettings { tab_size: required(defaults.editor.tab_size), hard_tabs: required(defaults.editor.hard_tabs), soft_wrap: required(defaults.editor.soft_wrap), @@ -128,7 +131,7 @@ impl Settings { format_on_save: required(defaults.editor.format_on_save), enable_language_server: required(defaults.editor.enable_language_server), }, - language_defaults: defaults.language_overrides, + language_defaults: defaults.languages, editor_overrides: Default::default(), language_overrides: Default::default(), theme: themes.get(&defaults.theme.unwrap()).unwrap(), @@ -138,7 +141,7 @@ impl Settings { pub fn with_language_defaults( mut self, language_name: impl Into>, - overrides: LanguageSettings, + overrides: EditorSettings, ) -> Self { self.language_defaults .insert(language_name.into(), overrides); @@ -171,7 +174,7 @@ impl Settings { fn language_setting(&self, language: Option<&str>, f: F) -> R where - F: Fn(&LanguageSettings) -> Option, + F: Fn(&EditorSettings) -> Option, { None.or_else(|| language.and_then(|l| self.language_overrides.get(l).and_then(&f))) .or_else(|| f(&self.editor_overrides)) @@ -189,7 +192,7 @@ impl Settings { hover_popover_enabled: true, vim_mode: false, autosave: Autosave::Off, - editor_defaults: LanguageSettings { + editor_defaults: EditorSettings { tab_size: Some(4.try_into().unwrap()), hard_tabs: Some(false), soft_wrap: Some(SoftWrap::None), @@ -255,7 +258,7 @@ impl Settings { data.editor.preferred_line_length, ); - for (language_name, settings) in data.language_overrides.clone().into_iter() { + for (language_name, settings) in data.languages.clone().into_iter() { let target = self .language_overrides .entry(language_name.into()) diff --git a/crates/zed/src/settings_file.rs b/crates/zed/src/settings_file.rs index 65cac2a496..da728f9dd6 100644 --- a/crates/zed/src/settings_file.rs +++ b/crates/zed/src/settings_file.rs @@ -93,7 +93,7 @@ pub async fn watch_keymap_file( mod tests { use super::*; use project::FakeFs; - use settings::{LanguageSettings, SoftWrap}; + use settings::{EditorSettings, SoftWrap}; #[gpui::test] async fn test_settings_from_files(cx: &mut gpui::TestAppContext) { @@ -128,7 +128,7 @@ mod tests { let settings = cx.read(Settings::test).with_language_defaults( "JavaScript", - LanguageSettings { + EditorSettings { tab_size: Some(2.try_into().unwrap()), ..Default::default() },