Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix text_threads_dir() non-compliance with XDG spec (#45771)

Marcus Mäkiläe2267aba12aa
diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs
index 02275d8cbd2..656188e249f 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<PathBuf> = 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<PathBuf> = 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<PathBuf> = 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<PathBuf> = OnceLock::new();
+ CONTEXTS_DIR.get_or_init(|| state_dir().join("conversations"))
+}
/// Returns the path to the contexts directory.
///