paths.rs

 1//! Paths to locations used by Zed.
 2
 3use std::path::{Path, PathBuf};
 4
 5use util::paths::HOME;
 6
 7lazy_static::lazy_static! {
 8    pub static ref CONFIG_DIR: PathBuf = if cfg!(target_os = "windows") {
 9        dirs::config_dir()
10            .expect("failed to determine RoamingAppData directory")
11            .join("Zed")
12    } else if cfg!(target_os = "linux") {
13        if let Ok(flatpak_xdg_config) = std::env::var("FLATPAK_XDG_CONFIG_HOME") {
14           flatpak_xdg_config.into()
15        } else {
16            dirs::config_dir().expect("failed to determine XDG_CONFIG_HOME directory")
17        }.join("zed")
18    } else {
19        HOME.join(".config").join("zed")
20    };
21    pub static ref CONTEXTS_DIR: PathBuf = if cfg!(target_os = "macos") {
22        CONFIG_DIR.join("conversations")
23    } else {
24        SUPPORT_DIR.join("conversations")
25    };
26    pub static ref PROMPTS_DIR: PathBuf = if cfg!(target_os = "macos") {
27        CONFIG_DIR.join("prompts")
28    } else {
29        SUPPORT_DIR.join("prompts")
30    };
31    pub static ref EMBEDDINGS_DIR: PathBuf = if cfg!(target_os = "macos") {
32        CONFIG_DIR.join("embeddings")
33    } else {
34        SUPPORT_DIR.join("embeddings")
35    };
36    pub static ref THEMES_DIR: PathBuf = CONFIG_DIR.join("themes");
37
38    pub static ref SUPPORT_DIR: PathBuf = if cfg!(target_os = "macos") {
39        HOME.join("Library/Application Support/Zed")
40    } else if cfg!(target_os = "linux") {
41        if let Ok(flatpak_xdg_data) = std::env::var("FLATPAK_XDG_DATA_HOME") {
42            flatpak_xdg_data.into()
43        } else {
44            dirs::data_local_dir().expect("failed to determine XDG_DATA_HOME directory")
45        }.join("zed")
46    } else if cfg!(target_os = "windows") {
47        dirs::data_local_dir()
48            .expect("failed to determine LocalAppData directory")
49            .join("Zed")
50    } else {
51        CONFIG_DIR.clone()
52    };
53    pub static ref LOGS_DIR: PathBuf = if cfg!(target_os = "macos") {
54        HOME.join("Library/Logs/Zed")
55    } else {
56        SUPPORT_DIR.join("logs")
57    };
58    pub static ref EXTENSIONS_DIR: PathBuf = SUPPORT_DIR.join("extensions");
59    pub static ref LANGUAGES_DIR: PathBuf = SUPPORT_DIR.join("languages");
60    pub static ref COPILOT_DIR: PathBuf = SUPPORT_DIR.join("copilot");
61    pub static ref SUPERMAVEN_DIR: PathBuf = SUPPORT_DIR.join("supermaven");
62    pub static ref DEFAULT_PRETTIER_DIR: PathBuf = SUPPORT_DIR.join("prettier");
63    pub static ref DB_DIR: PathBuf = SUPPORT_DIR.join("db");
64    pub static ref CRASHES_DIR: Option<PathBuf> = cfg!(target_os = "macos")
65        .then_some(HOME.join("Library/Logs/DiagnosticReports"));
66    pub static ref CRASHES_RETIRED_DIR: Option<PathBuf> = CRASHES_DIR
67        .as_ref()
68        .map(|dir| dir.join("Retired"));
69
70    pub static ref SETTINGS: PathBuf = CONFIG_DIR.join("settings.json");
71    pub static ref KEYMAP: PathBuf = CONFIG_DIR.join("keymap.json");
72    pub static ref TASKS: PathBuf = CONFIG_DIR.join("tasks.json");
73    pub static ref LAST_USERNAME: PathBuf = CONFIG_DIR.join("last-username.txt");
74    pub static ref LOG: PathBuf = LOGS_DIR.join("Zed.log");
75    pub static ref OLD_LOG: PathBuf = LOGS_DIR.join("Zed.log.old");
76    pub static ref LOCAL_SETTINGS_RELATIVE_PATH: &'static Path = Path::new(".zed/settings.json");
77    pub static ref LOCAL_TASKS_RELATIVE_PATH: &'static Path = Path::new(".zed/tasks.json");
78    pub static ref LOCAL_VSCODE_TASKS_RELATIVE_PATH: &'static Path = Path::new(".vscode/tasks.json");
79    pub static ref TEMP_DIR: PathBuf = if cfg!(target_os = "windows") {
80        dirs::cache_dir()
81            .expect("failed to determine LocalAppData directory")
82            .join("Zed")
83    } else if cfg!(target_os = "linux") {
84        if let Ok(flatpak_xdg_cache) = std::env::var("FLATPAK_XDG_CACHE_HOME") {
85            flatpak_xdg_cache.into()
86        } else {
87            dirs::cache_dir().expect("failed to determine XDG_CACHE_HOME directory")
88        }.join("zed")
89    } else {
90        HOME.join(".cache").join("zed")
91    };
92}