diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs index 02275d8cbd26ab86435476c5adeaf81ec09a29e9..656188e249fc864e1328c8f458bdc46aa7eaea3a 100644 --- a/crates/paths/src/paths.rs +++ b/crates/paths/src/paths.rs @@ -122,6 +122,29 @@ pub fn data_dir() -> &'static PathBuf { }) } +pub fn state_dir() -> &'static PathBuf { + static STATE_DIR: OnceLock = OnceLock::new(); + STATE_DIR.get_or_init(|| { + if cfg!(target_os = "macos") { + return home_dir().join(".local").join("state").join("Zed"); + } + + if cfg!(any(target_os = "linux", target_os = "freebsd")) { + return if let Ok(flatpak_xdg_state) = std::env::var("FLATPAK_XDG_STATE_HOME") { + flatpak_xdg_state.into() + } else { + dirs::state_dir().expect("failed to determine XDG_STATE_HOME directory") + } + .join("zed"); + } else { + // Windows + return dirs::data_local_dir() + .expect("failed to determine LocalAppData directory") + .join("Zed"); + } + }) +} + /// Returns the path to the temp directory used by Zed. pub fn temp_dir() -> &'static PathBuf { static TEMP_DIR: OnceLock = OnceLock::new(); @@ -287,10 +310,9 @@ pub fn snippets_dir() -> &'static PathBuf { SNIPPETS_DIR.get_or_init(|| config_dir().join("snippets")) } -/// Returns the path to the contexts directory. -/// -/// This is where the saved contexts from the Assistant are stored. -pub fn text_threads_dir() -> &'static PathBuf { +// Returns old path to contexts directory. +// Fallback +fn text_threads_dir_fallback() -> &'static PathBuf { static CONTEXTS_DIR: OnceLock = OnceLock::new(); CONTEXTS_DIR.get_or_init(|| { if cfg!(target_os = "macos") { @@ -300,6 +322,17 @@ pub fn text_threads_dir() -> &'static PathBuf { } }) } +/// Returns the path to the contexts directory. +/// +/// This is where the saved contexts from the Assistant are stored. +pub fn text_threads_dir() -> &'static PathBuf { + let fallback_dir = text_threads_dir_fallback(); + if fallback_dir.exists() { + return fallback_dir; + } + static CONTEXTS_DIR: OnceLock = OnceLock::new(); + CONTEXTS_DIR.get_or_init(|| state_dir().join("conversations")) +} /// Returns the path to the contexts directory. ///