From cfe3ebd2b30a9d1523c4e317d2d5d596c24f6a7f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 29 Jul 2022 09:12:36 +0200 Subject: [PATCH 1/3] Use XDG-compliant directories for config and cache files --- crates/project/src/db.rs | 10 ++++----- crates/zed/src/main.rs | 48 +++++++++++++--------------------------- crates/zed/src/zed.rs | 26 +++++++++++++++------- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/crates/project/src/db.rs b/crates/project/src/db.rs index bc125e4303..0b630bf256 100644 --- a/crates/project/src/db.rs +++ b/crates/project/src/db.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use std::path::PathBuf; +use std::path::Path; use std::sync::Arc; pub struct Db(DbStore); @@ -16,8 +16,8 @@ enum DbStore { impl Db { /// Open or create a database at the given file path. - pub fn open(path: PathBuf) -> Result> { - let db = rocksdb::DB::open_default(&path)?; + pub fn open(path: &Path) -> Result> { + let db = rocksdb::DB::open_default(path)?; Ok(Arc::new(Self(DbStore::Real(db)))) } @@ -125,7 +125,7 @@ mod tests { fn test_db() { let dir = TempDir::new("db-test").unwrap(); let fake_db = Db::open_fake(); - let real_db = Db::open(dir.path().join("test.db")).unwrap(); + let real_db = Db::open(&dir.path().join("test.db")).unwrap(); for db in [&real_db, &fake_db] { assert_eq!( @@ -152,7 +152,7 @@ mod tests { drop(real_db); - let real_db = Db::open(dir.path().join("test.db")).unwrap(); + let real_db = Db::open(&dir.path().join("test.db")).unwrap(); assert_eq!( real_db.read(["key-1", "key-2", "key-3"]).unwrap(), &[Some("one".as_bytes().to_vec()), None, None,] diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 2ca1403b6c..d800901b49 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -28,15 +28,7 @@ use project::{Fs, ProjectStore}; use serde_json::json; use settings::{self, KeymapFileContent, Settings, SettingsFileContent}; use smol::process::Command; -use std::{ - env, - ffi::OsStr, - fs, panic, - path::{Path, PathBuf}, - sync::Arc, - thread, - time::Duration, -}; +use std::{env, ffi::OsStr, fs, panic, path::PathBuf, sync::Arc, thread, time::Duration}; use terminal; use theme::ThemeRegistry; use util::{ResultExt, TryFutureExt}; @@ -50,21 +42,19 @@ use zed::{ fn main() { let http = http::client(); - let home_dir = dirs::home_dir().expect("could not find home dir"); - let db_dir_path = home_dir.join("Library/Application Support/Zed"); - let logs_dir_path = home_dir.join("Library/Logs/Zed"); - fs::create_dir_all(&db_dir_path).expect("could not create database path"); - fs::create_dir_all(&logs_dir_path).expect("could not create logs path"); - init_logger(&logs_dir_path); + fs::create_dir_all(&*zed::LANGUAGES_DIR_PATH).expect("could not create languages path"); + fs::create_dir_all(&*zed::DB_DIR_PATH).expect("could not create database path"); + fs::create_dir_all(&*zed::LOGS_DIR_PATH).expect("could not create logs path"); + init_logger(); log::info!("========== starting zed =========="); let mut app = gpui::App::new(Assets).unwrap(); let app_version = ZED_APP_VERSION .or_else(|| app.platform().app_version().ok()) .map_or("dev".to_string(), |v| v.to_string()); - init_panic_hook(logs_dir_path, app_version, http.clone(), app.background()); + init_panic_hook(app_version, http.clone(), app.background()); let db = app.background().spawn(async move { - project::Db::open(db_dir_path.join("zed.db")) + project::Db::open(&*zed::DB_PATH) .log_err() .unwrap_or(project::Db::null()) }); @@ -100,7 +90,7 @@ fn main() { app.run(move |cx| { let client = client::Client::new(http.clone()); let mut languages = LanguageRegistry::new(login_shell_env_loaded); - languages.set_language_server_download_dir(zed::ROOT_PATH.clone()); + languages.set_language_server_download_dir(zed::LANGUAGES_DIR_PATH.clone()); let languages = Arc::new(languages); let init_languages = cx .background() @@ -205,42 +195,34 @@ fn main() { }); } -fn init_logger(logs_dir_path: &Path) { +fn init_logger() { if stdout_is_a_pty() { env_logger::init(); } else { let level = LevelFilter::Info; - let log_file_path = logs_dir_path.join("Zed.log"); // Prevent log file from becoming too large. const MAX_LOG_BYTES: u64 = 1 * 1024 * 1024; - if fs::metadata(&log_file_path).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES) { - let _ = fs::rename(&log_file_path, logs_dir_path.join("Zed.log.old")); + if fs::metadata(&*zed::LOG_PATH).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES) { + let _ = fs::rename(&*zed::LOG_PATH, &*zed::OLD_LOG_PATH); } let log_file = OpenOptions::new() .create(true) .append(true) - .open(log_file_path) + .open(&*zed::LOG_PATH) .expect("could not open logfile"); simplelog::WriteLogger::init(level, simplelog::Config::default(), log_file) .expect("could not initialize logger"); } } -fn init_panic_hook( - logs_dir_path: PathBuf, - app_version: String, - http: Arc, - background: Arc, -) { +fn init_panic_hook(app_version: String, http: Arc, background: Arc) { background .spawn({ - let logs_dir_path = logs_dir_path.clone(); - async move { let panic_report_url = format!("{}/api/panic", &*client::ZED_SERVER_URL); - let mut children = smol::fs::read_dir(&logs_dir_path).await?; + let mut children = smol::fs::read_dir(&*zed::LOGS_DIR_PATH).await?; while let Some(child) = children.next().await { let child = child?; let child_path = child.path(); @@ -330,7 +312,7 @@ fn init_panic_hook( let panic_filename = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string(); fs::write( - logs_dir_path.join(format!("zed-{}-{}.panic", app_version, panic_filename)), + zed::LOGS_DIR_PATH.join(format!("zed-{}-{}.panic", app_version, panic_filename)), &message, ) .context("error writing panic to disk") diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 6ed9b40a18..fb8496293e 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -31,6 +31,7 @@ use serde::Deserialize; use serde_json::to_string_pretty; use settings::{keymap_file_json_schema, settings_file_json_schema, Settings}; use std::{ + env, path::{Path, PathBuf}, str, sync::Arc, @@ -67,13 +68,22 @@ actions!( const MIN_FONT_SIZE: f32 = 6.0; lazy_static! { - pub static ref HOME_PATH: PathBuf = - dirs::home_dir().expect("failed to determine home directory"); - pub static ref LOG_PATH: PathBuf = HOME_PATH.join("Library/Logs/Zed/Zed.log"); - pub static ref OLD_LOG_PATH: PathBuf = HOME_PATH.join("Library/Logs/Zed/Zed.log.old"); - pub static ref ROOT_PATH: PathBuf = HOME_PATH.join(".zed"); - pub static ref SETTINGS_PATH: PathBuf = ROOT_PATH.join("settings.json"); - pub static ref KEYMAP_PATH: PathBuf = ROOT_PATH.join("keymap.json"); + static ref HOME_PATH: PathBuf = dirs::home_dir().expect("failed to determine home directory"); + static ref CACHE_DIR_PATH: PathBuf = dirs::cache_dir() + .expect("failed to determine cache directory") + .join("Zed"); + static ref CONFIG_DIR_PATH: PathBuf = env::var_os("XDG_CONFIG_HOME") + .map(|home| home.into()) + .unwrap_or_else(|| HOME_PATH.join(".config")) + .join("zed"); + pub static ref LOGS_DIR_PATH: PathBuf = HOME_PATH.join("Library/Logs/Zed"); + pub static ref LANGUAGES_DIR_PATH: PathBuf = CACHE_DIR_PATH.join("languages"); + pub static ref DB_DIR_PATH: PathBuf = CACHE_DIR_PATH.join("db"); + pub static ref DB_PATH: PathBuf = DB_DIR_PATH.join("zed.db"); + pub static ref SETTINGS_PATH: PathBuf = CONFIG_DIR_PATH.join("settings.json"); + pub static ref KEYMAP_PATH: PathBuf = CONFIG_DIR_PATH.join("keymap.json"); + pub static ref LOG_PATH: PathBuf = LOGS_DIR_PATH.join("Zed.log"); + pub static ref OLD_LOG_PATH: PathBuf = LOGS_DIR_PATH.join("Zed.log.old"); } pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { @@ -399,7 +409,7 @@ fn open_config_file( 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_dir(&CONFIG_DIR_PATH).await?; fs.create_file(path, Default::default()).await?; fs.save(path, &default_content(), Default::default()) .await?; From 5f6e4c7d91d6cdab2e70087f9c64bb42317f566a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 29 Jul 2022 09:27:21 +0200 Subject: [PATCH 2/3] Extract all zed config/cache paths into a `paths` module --- crates/zed/src/main.rs | 25 +++++++++++++------------ crates/zed/src/paths.rs | 22 ++++++++++++++++++++++ crates/zed/src/zed.rs | 38 +++++++------------------------------- 3 files changed, 42 insertions(+), 43 deletions(-) create mode 100644 crates/zed/src/paths.rs diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index d800901b49..7d24eaa88f 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -42,9 +42,9 @@ use zed::{ fn main() { let http = http::client(); - fs::create_dir_all(&*zed::LANGUAGES_DIR_PATH).expect("could not create languages path"); - fs::create_dir_all(&*zed::DB_DIR_PATH).expect("could not create database path"); - fs::create_dir_all(&*zed::LOGS_DIR_PATH).expect("could not create logs path"); + fs::create_dir_all(&*zed::paths::LANGUAGES_DIR).expect("could not create languages path"); + fs::create_dir_all(&*zed::paths::DB_DIR).expect("could not create database path"); + fs::create_dir_all(&*zed::paths::LOGS_DIR).expect("could not create logs path"); init_logger(); log::info!("========== starting zed =========="); @@ -54,7 +54,7 @@ fn main() { .map_or("dev".to_string(), |v| v.to_string()); init_panic_hook(app_version, http.clone(), app.background()); let db = app.background().spawn(async move { - project::Db::open(&*zed::DB_PATH) + project::Db::open(&*zed::paths::DB) .log_err() .unwrap_or(project::Db::null()) }); @@ -90,7 +90,7 @@ fn main() { app.run(move |cx| { let client = client::Client::new(http.clone()); let mut languages = LanguageRegistry::new(login_shell_env_loaded); - languages.set_language_server_download_dir(zed::LANGUAGES_DIR_PATH.clone()); + languages.set_language_server_download_dir(zed::paths::LANGUAGES_DIR.clone()); let languages = Arc::new(languages); let init_languages = cx .background() @@ -203,14 +203,15 @@ fn init_logger() { // Prevent log file from becoming too large. const MAX_LOG_BYTES: u64 = 1 * 1024 * 1024; - if fs::metadata(&*zed::LOG_PATH).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES) { - let _ = fs::rename(&*zed::LOG_PATH, &*zed::OLD_LOG_PATH); + if fs::metadata(&*zed::paths::LOG).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES) + { + let _ = fs::rename(&*zed::paths::LOG, &*zed::paths::OLD_LOG); } let log_file = OpenOptions::new() .create(true) .append(true) - .open(&*zed::LOG_PATH) + .open(&*zed::paths::LOG) .expect("could not open logfile"); simplelog::WriteLogger::init(level, simplelog::Config::default(), log_file) .expect("could not initialize logger"); @@ -222,7 +223,7 @@ fn init_panic_hook(app_version: String, http: Arc, background: A .spawn({ async move { let panic_report_url = format!("{}/api/panic", &*client::ZED_SERVER_URL); - let mut children = smol::fs::read_dir(&*zed::LOGS_DIR_PATH).await?; + let mut children = smol::fs::read_dir(&*zed::paths::LOGS_DIR).await?; while let Some(child) = children.next().await { let child = child?; let child_path = child.path(); @@ -312,7 +313,7 @@ fn init_panic_hook(app_version: String, http: Arc, background: A let panic_filename = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string(); fs::write( - zed::LOGS_DIR_PATH.join(format!("zed-{}-{}.panic", app_version, panic_filename)), + zed::paths::LOGS_DIR.join(format!("zed-{}-{}.panic", app_version, panic_filename)), &message, ) .context("error writing panic to disk") @@ -446,8 +447,8 @@ fn load_config_files( .clone() .spawn(async move { let settings_file = - WatchedJsonFile::new(fs.clone(), &executor, zed::SETTINGS_PATH.clone()).await; - let keymap_file = WatchedJsonFile::new(fs, &executor, zed::KEYMAP_PATH.clone()).await; + WatchedJsonFile::new(fs.clone(), &executor, zed::paths::SETTINGS.clone()).await; + let keymap_file = WatchedJsonFile::new(fs, &executor, zed::paths::KEYMAP.clone()).await; tx.send((settings_file, keymap_file)).ok() }) .detach(); diff --git a/crates/zed/src/paths.rs b/crates/zed/src/paths.rs new file mode 100644 index 0000000000..763c4d1070 --- /dev/null +++ b/crates/zed/src/paths.rs @@ -0,0 +1,22 @@ +use std::{env, path::PathBuf}; + +use lazy_static::lazy_static; + +lazy_static! { + static ref HOME: PathBuf = dirs::home_dir().expect("failed to determine home directory"); + static ref CACHE_DIR: PathBuf = dirs::cache_dir() + .expect("failed to determine cache directory") + .join("Zed"); + pub static ref CONFIG_DIR: PathBuf = env::var_os("XDG_CONFIG_HOME") + .map(|home| home.into()) + .unwrap_or_else(|| HOME.join(".config")) + .join("zed"); + pub static ref LOGS_DIR: PathBuf = HOME.join("Library/Logs/Zed"); + pub static ref LANGUAGES_DIR: PathBuf = CACHE_DIR.join("languages"); + pub static ref DB_DIR: PathBuf = CACHE_DIR.join("db"); + pub static ref DB: PathBuf = DB_DIR.join("zed.db"); + pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json"); + pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json"); + pub static ref LOG: PathBuf = LOGS_DIR.join("Zed.log"); + pub static ref OLD_LOG: PathBuf = LOGS_DIR.join("Zed.log.old"); +} diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index fb8496293e..20ecf68e8d 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -1,6 +1,7 @@ mod feedback; pub mod languages; pub mod menus; +pub mod paths; pub mod settings_file; #[cfg(any(test, feature = "test-support"))] pub mod test; @@ -22,7 +23,6 @@ use gpui::{ AssetSource, AsyncAppContext, ViewContext, }; use language::Rope; -use lazy_static::lazy_static; pub use lsp; pub use project::{self, fs}; use project_panel::ProjectPanel; @@ -30,12 +30,7 @@ use search::{BufferSearchBar, ProjectSearchBar}; use serde::Deserialize; use serde_json::to_string_pretty; use settings::{keymap_file_json_schema, settings_file_json_schema, Settings}; -use std::{ - env, - path::{Path, PathBuf}, - str, - sync::Arc, -}; +use std::{env, path::Path, str, sync::Arc}; use util::ResultExt; pub use workspace; use workspace::{sidebar::Side, AppState, Workspace}; @@ -67,25 +62,6 @@ actions!( const MIN_FONT_SIZE: f32 = 6.0; -lazy_static! { - static ref HOME_PATH: PathBuf = dirs::home_dir().expect("failed to determine home directory"); - static ref CACHE_DIR_PATH: PathBuf = dirs::cache_dir() - .expect("failed to determine cache directory") - .join("Zed"); - static ref CONFIG_DIR_PATH: PathBuf = env::var_os("XDG_CONFIG_HOME") - .map(|home| home.into()) - .unwrap_or_else(|| HOME_PATH.join(".config")) - .join("zed"); - pub static ref LOGS_DIR_PATH: PathBuf = HOME_PATH.join("Library/Logs/Zed"); - pub static ref LANGUAGES_DIR_PATH: PathBuf = CACHE_DIR_PATH.join("languages"); - pub static ref DB_DIR_PATH: PathBuf = CACHE_DIR_PATH.join("db"); - pub static ref DB_PATH: PathBuf = DB_DIR_PATH.join("zed.db"); - pub static ref SETTINGS_PATH: PathBuf = CONFIG_DIR_PATH.join("settings.json"); - pub static ref KEYMAP_PATH: PathBuf = CONFIG_DIR_PATH.join("keymap.json"); - pub static ref LOG_PATH: PathBuf = LOGS_DIR_PATH.join("Zed.log"); - pub static ref OLD_LOG_PATH: PathBuf = LOGS_DIR_PATH.join("Zed.log.old"); -} - pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { cx.add_action(about); cx.add_global_action(quit); @@ -122,7 +98,7 @@ 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(&paths::SETTINGS, app_state.clone(), cx, || { str::from_utf8( Assets .load("settings/initial_user_settings.json") @@ -143,7 +119,7 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { 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, || Default::default()); + open_config_file(&paths::KEYMAP, app_state.clone(), cx, || Default::default()); } }); cx.add_action({ @@ -409,7 +385,7 @@ fn open_config_file( cx.spawn(|workspace, mut cx| async move { let fs = &app_state.fs; if !fs.is_file(path).await { - fs.create_dir(&CONFIG_DIR_PATH).await?; + fs.create_dir(&paths::CONFIG_DIR).await?; fs.create_file(path, Default::default()).await?; fs.save(path, &default_content(), Default::default()) .await?; @@ -437,8 +413,8 @@ fn open_log_file( workspace.with_local_workspace(cx, app_state.clone(), |_, cx| { cx.spawn_weak(|workspace, mut cx| async move { let (old_log, new_log) = futures::join!( - app_state.fs.load(&OLD_LOG_PATH), - app_state.fs.load(&LOG_PATH) + app_state.fs.load(&paths::OLD_LOG), + app_state.fs.load(&paths::LOG) ); if let Some(workspace) = workspace.upgrade(&cx) { From f2d92d640d08414bbe14800cb9f2655bbf0ee0cc Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 29 Jul 2022 09:57:38 +0200 Subject: [PATCH 3/3] Copy setting and keymap files from legacy config locations --- crates/zed/src/main.rs | 26 +++++++++++++++++++++++--- crates/zed/src/paths.rs | 28 +++++++++++++++------------- crates/zed/src/zed.rs | 10 +++++++--- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 7d24eaa88f..ed718272d8 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -42,9 +42,7 @@ use zed::{ fn main() { let http = http::client(); - fs::create_dir_all(&*zed::paths::LANGUAGES_DIR).expect("could not create languages path"); - fs::create_dir_all(&*zed::paths::DB_DIR).expect("could not create database path"); - fs::create_dir_all(&*zed::paths::LOGS_DIR).expect("could not create logs path"); + init_paths(); init_logger(); log::info!("========== starting zed =========="); @@ -195,6 +193,28 @@ fn main() { }); } +fn init_paths() { + fs::create_dir_all(&*zed::paths::CONFIG_DIR).expect("could not create config path"); + fs::create_dir_all(&*zed::paths::LANGUAGES_DIR).expect("could not create languages path"); + fs::create_dir_all(&*zed::paths::DB_DIR).expect("could not create database path"); + fs::create_dir_all(&*zed::paths::LOGS_DIR).expect("could not create logs path"); + + // Copy setting files from legacy locations. TODO: remove this after a few releases. + thread::spawn(|| { + if fs::metadata(&*zed::paths::legacy::SETTINGS).is_ok() + && fs::metadata(&*zed::paths::SETTINGS).is_err() + { + fs::copy(&*zed::paths::legacy::SETTINGS, &*zed::paths::SETTINGS).log_err(); + } + + if fs::metadata(&*zed::paths::legacy::KEYMAP).is_ok() + && fs::metadata(&*zed::paths::KEYMAP).is_err() + { + fs::copy(&*zed::paths::legacy::KEYMAP, &*zed::paths::KEYMAP).log_err(); + } + }); +} + fn init_logger() { if stdout_is_a_pty() { env_logger::init(); diff --git a/crates/zed/src/paths.rs b/crates/zed/src/paths.rs index 763c4d1070..6643cc0fe6 100644 --- a/crates/zed/src/paths.rs +++ b/crates/zed/src/paths.rs @@ -1,22 +1,24 @@ -use std::{env, path::PathBuf}; +use std::path::PathBuf; -use lazy_static::lazy_static; - -lazy_static! { +lazy_static::lazy_static! { static ref HOME: PathBuf = dirs::home_dir().expect("failed to determine home directory"); - static ref CACHE_DIR: PathBuf = dirs::cache_dir() - .expect("failed to determine cache directory") - .join("Zed"); - pub static ref CONFIG_DIR: PathBuf = env::var_os("XDG_CONFIG_HOME") - .map(|home| home.into()) - .unwrap_or_else(|| HOME.join(".config")) - .join("zed"); + pub static ref CONFIG_DIR: PathBuf = HOME.join(".config").join("zed"); pub static ref LOGS_DIR: PathBuf = HOME.join("Library/Logs/Zed"); - pub static ref LANGUAGES_DIR: PathBuf = CACHE_DIR.join("languages"); - pub static ref DB_DIR: PathBuf = CACHE_DIR.join("db"); + pub static ref LANGUAGES_DIR: PathBuf = HOME.join("Library/Application Support/Zed/languages"); + pub static ref DB_DIR: PathBuf = HOME.join("Library/Application Support/Zed/db"); pub static ref DB: PathBuf = DB_DIR.join("zed.db"); pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json"); pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json"); pub static ref LOG: PathBuf = LOGS_DIR.join("Zed.log"); pub static ref OLD_LOG: PathBuf = LOGS_DIR.join("Zed.log.old"); } + +pub mod legacy { + use std::path::PathBuf; + + lazy_static::lazy_static! { + static ref CONFIG_DIR: PathBuf = super::HOME.join(".zed"); + pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json"); + pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json"); + } +} diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 20ecf68e8d..2f683d8e8e 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -223,11 +223,11 @@ pub fn initialize_workspace( }, "schemas": [ { - "fileMatch": [".zed/settings.json"], + "fileMatch": [schema_file_match(&*paths::SETTINGS)], "schema": settings_file_json_schema(theme_names, language_names), }, { - "fileMatch": [".zed/keymap.json"], + "fileMatch": [schema_file_match(&*paths::KEYMAP)], "schema": keymap_file_json_schema(&action_names), } ] @@ -385,7 +385,6 @@ fn open_config_file( cx.spawn(|workspace, mut cx| async move { let fs = &app_state.fs; if !fs.is_file(path).await { - fs.create_dir(&paths::CONFIG_DIR).await?; fs.create_file(path, Default::default()).await?; fs.save(path, &default_content(), Default::default()) .await?; @@ -481,6 +480,11 @@ fn open_bundled_config_file( }); } +fn schema_file_match(path: &Path) -> &Path { + path.strip_prefix(path.parent().unwrap().parent().unwrap()) + .unwrap() +} + #[cfg(test)] mod tests { use super::*;