diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 7d24eaa88f3bd9e81dad46f58af0bbb2a1f24afc..ed718272d8fb50be0d4e96da9434ed9e4c854836 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 763c4d10706fa88c823480f20a1e4889aa5f3225..6643cc0fe6d40c7d91038e0634eab8b8f27de0cf 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 20ecf68e8d421370a6483162c93d27e92703056d..2f683d8e8e4093a728117d6a8f637f317957e33c 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::*;