diff --git a/assets/default-settings.json b/assets/settings/default.json similarity index 100% rename from assets/default-settings.json rename to assets/settings/default.json diff --git a/assets/settings/header-comments.json b/assets/settings/header-comments.json new file mode 100644 index 0000000000..6180d310df --- /dev/null +++ b/assets/settings/header-comments.json @@ -0,0 +1,8 @@ +// Zed settings +// +// For information on how to configure Zed, see the Zed +// documentation: https://zed.dev/docs/configuring-zed +// +// To see all of Zed's default settings without changing your +// custom settings, run the `open default settings` command +// from the command palette or from `Zed` application menu. diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 219351896a..f976eb3054 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -107,7 +107,7 @@ impl Settings { } let defaults: SettingsFileContent = parse_json_with_comments( - str::from_utf8(assets.load("default-settings.json").unwrap().as_ref()).unwrap(), + str::from_utf8(assets.load("settings/default.json").unwrap().as_ref()).unwrap(), ) .unwrap(); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 1bfa75b920..d27a5b7c5b 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -18,8 +18,9 @@ use gpui::{ geometry::vector::vec2f, impl_actions, platform::{WindowBounds, WindowOptions}, - AsyncAppContext, ViewContext, + AssetSource, AsyncAppContext, ViewContext, }; +use language::Rope; use lazy_static::lazy_static; pub use lsp; pub use project::{self, fs}; @@ -100,13 +101,22 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { cx.add_action({ let app_state = app_state.clone(); move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext| { - open_config_file(&SETTINGS_PATH, app_state.clone(), cx); + open_config_file(&SETTINGS_PATH, app_state.clone(), cx, || { + let header = Assets.load("settings/header-comments.json").unwrap(); + let json = Assets.load("settings/default.json").unwrap(); + let header = str::from_utf8(header.as_ref()).unwrap(); + let json = str::from_utf8(json.as_ref()).unwrap(); + let mut content = Rope::new(); + content.push(header); + content.push(json); + content + }); } }); cx.add_action({ let app_state = app_state.clone(); move |_: &mut Workspace, _: &OpenKeymap, cx: &mut ViewContext| { - open_config_file(&KEYMAP_PATH, app_state.clone(), cx); + open_config_file(&KEYMAP_PATH, app_state.clone(), cx, || Default::default()); } }); cx.add_action({ @@ -129,7 +139,7 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { open_bundled_config_file( workspace, app_state.clone(), - "default-settings.json", + "settings/default.json", "Default Settings", cx, ); @@ -367,12 +377,15 @@ fn open_config_file( path: &'static Path, app_state: Arc, cx: &mut ViewContext, + default_content: impl 'static + Send + FnOnce() -> Rope, ) { cx.spawn(|workspace, mut cx| async move { let fs = &app_state.fs; if !fs.is_file(path).await { fs.create_dir(&ROOT_PATH).await?; fs.create_file(path, Default::default()).await?; + fs.save(path, &default_content(), Default::default()) + .await?; } workspace