Skip to repository content673 lines · 24.8 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:32:14.031Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
paths.rs
1//! Paths to application data and configuration.
2
3use std::env;
4use std::path::{Path, PathBuf};
5use std::sync::{LazyLock, OnceLock};
6
7use util::paths::SanitizedPath;
8pub use util::paths::home_dir;
9use util::rel_path::RelPath;
10
11/// A default editorconfig file name to use when resolving project settings.
12pub const EDITORCONFIG_NAME: &str = ".editorconfig";
13
14pub use app_identity::BINARY_NAME;
15
16/// Returns the channel-specific application display name used for data roots.
17pub fn app_name() -> &'static str {
18 app_identity::CHANNEL.display_name()
19}
20
21/// Returns the channel-specific application slug used for XDG-style roots.
22pub fn app_storage_slug() -> &'static str {
23 app_identity::CHANNEL.storage_slug()
24}
25
26/// The custom data directory, if one was set.
27///
28/// Two Omega instances pointed at different data directories share no state,
29/// so they are not the same instance. The macOS single-instance lock keys its
30/// port on release channel and uid only, which meant a second instance with
31/// its own `--user-data-dir` was refused by the first — and `ZED_RELEASE_CHANNEL`
32/// is `debug_assertions`-only, so a release build had no way out. Proving
33/// anything on a clean profile therefore required quitting the running Omega.
34pub fn custom_data_dir() -> Option<&'static PathBuf> {
35 CUSTOM_DATA_DIR.get()
36}
37
38/// A custom data directory override, set only by `set_custom_data_dir`.
39/// This is used to override the default data directory location.
40/// The directory will be created if it doesn't exist when set.
41static CUSTOM_DATA_DIR: OnceLock<PathBuf> = OnceLock::new();
42
43/// The resolved data directory, combining custom override or platform defaults.
44/// This is set once and cached for subsequent calls.
45/// On macOS, this is `~/Library/Application Support/<Omega channel>`.
46/// On Linux/FreeBSD, this is `$XDG_DATA_HOME/<omega-channel>`.
47/// On Windows, this is `%LOCALAPPDATA%\<Omega channel>`.
48static CURRENT_DATA_DIR: OnceLock<PathBuf> = OnceLock::new();
49
50/// The resolved config directory, combining custom override or platform defaults.
51/// This is set once and cached for subsequent calls.
52/// On macOS, this is `~/.config/<omega-channel>`.
53/// On Linux/FreeBSD, this is `$XDG_CONFIG_HOME/<omega-channel>`.
54/// On Windows, this is `%APPDATA%\<Omega channel>`.
55static CONFIG_DIR: OnceLock<PathBuf> = OnceLock::new();
56
57/// Returns the relative path to the zed_server directory on the ssh host.
58pub fn remote_server_dir_relative() -> &'static RelPath {
59 static CACHED: LazyLock<&'static RelPath> =
60 LazyLock::new(|| RelPath::from_unix_str(".zed_server").unwrap());
61 *CACHED
62}
63
64// Remove this once 223 goes stable
65/// Returns the relative path to the zed_wsl_server directory on the wsl host.
66pub fn remote_wsl_server_dir_relative() -> &'static RelPath {
67 static CACHED: LazyLock<&'static RelPath> =
68 LazyLock::new(|| RelPath::from_unix_str(".zed_wsl_server").unwrap());
69 *CACHED
70}
71
72/// Sets a custom directory for all user data, overriding the default data directory.
73/// This function must be called before any other path operations that depend on the data directory.
74/// The directory's path will be canonicalized to an absolute path by a blocking FS operation.
75/// The directory will be created if it doesn't exist.
76///
77/// # Arguments
78///
79/// * `dir` - The path to use as the custom data directory. This will be used as the base
80/// directory for all user data, including databases, extensions, and logs.
81///
82/// # Returns
83///
84/// A reference to the static `PathBuf` containing the custom data directory path.
85///
86/// # Panics
87///
88/// Panics if:
89/// * Called after the data directory has been initialized (e.g., via `data_dir` or `config_dir`)
90/// * The directory's path cannot be canonicalized to an absolute path
91/// * The directory cannot be created
92pub fn set_custom_data_dir(dir: &str) -> &'static PathBuf {
93 if CURRENT_DATA_DIR.get().is_some() || CONFIG_DIR.get().is_some() {
94 panic!("set_custom_data_dir called after data_dir or config_dir was initialized");
95 }
96 CUSTOM_DATA_DIR.get_or_init(|| {
97 let path = PathBuf::from(dir);
98 std::fs::create_dir_all(&path).expect("failed to create custom data directory");
99 let canonicalized = path
100 .canonicalize()
101 .expect("failed to canonicalize custom data directory's path to an absolute path");
102 // On Windows, `canonicalize` produces extended-length paths prefixed
103 // with `\\?\`. Strip that prefix so downstream consumers (e.g.
104 // Node.js language servers) that receive derived paths as arguments
105 // don't choke on the verbatim syntax.
106 SanitizedPath::new(&canonicalized).as_path().to_path_buf()
107 })
108}
109
110/// Returns the path to the configuration directory used by Zed.
111pub fn config_dir() -> &'static PathBuf {
112 CONFIG_DIR.get_or_init(|| {
113 if let Some(custom_dir) = CUSTOM_DATA_DIR.get() {
114 custom_dir.join("config")
115 } else if cfg!(target_os = "windows") {
116 dirs::config_dir()
117 .expect("failed to determine RoamingAppData directory")
118 .join(app_name())
119 } else if cfg!(any(target_os = "linux", target_os = "freebsd")) {
120 if let Ok(flatpak_xdg_config) = std::env::var("FLATPAK_XDG_CONFIG_HOME") {
121 flatpak_xdg_config.into()
122 } else {
123 dirs::config_dir().expect("failed to determine XDG_CONFIG_HOME directory")
124 }
125 .join(app_storage_slug())
126 } else {
127 home_dir().join(".config").join(app_storage_slug())
128 }
129 })
130}
131
132/// Returns the path to the data directory used by Zed.
133pub fn data_dir() -> &'static PathBuf {
134 CURRENT_DATA_DIR.get_or_init(|| {
135 if let Some(custom_dir) = CUSTOM_DATA_DIR.get() {
136 custom_dir.clone()
137 } else if cfg!(target_os = "macos") {
138 home_dir()
139 .join("Library/Application Support")
140 .join(app_name())
141 } else if cfg!(any(target_os = "linux", target_os = "freebsd")) {
142 if let Ok(flatpak_xdg_data) = std::env::var("FLATPAK_XDG_DATA_HOME") {
143 flatpak_xdg_data.into()
144 } else {
145 dirs::data_local_dir().expect("failed to determine XDG_DATA_HOME directory")
146 }
147 .join(app_storage_slug())
148 } else if cfg!(target_os = "windows") {
149 dirs::data_local_dir()
150 .expect("failed to determine LocalAppData directory")
151 .join(app_name())
152 } else {
153 config_dir().clone() // Fallback
154 }
155 })
156}
157
158pub fn state_dir() -> &'static PathBuf {
159 static STATE_DIR: OnceLock<PathBuf> = OnceLock::new();
160 STATE_DIR.get_or_init(|| {
161 if let Some(custom_dir) = CUSTOM_DATA_DIR.get() {
162 return custom_dir.join("state");
163 }
164
165 if cfg!(target_os = "macos") {
166 return home_dir()
167 .join(".local")
168 .join("state")
169 .join(app_storage_slug());
170 }
171
172 if cfg!(any(target_os = "linux", target_os = "freebsd")) {
173 return if let Ok(flatpak_xdg_state) = std::env::var("FLATPAK_XDG_STATE_HOME") {
174 flatpak_xdg_state.into()
175 } else {
176 dirs::state_dir().expect("failed to determine XDG_STATE_HOME directory")
177 }
178 .join(app_storage_slug());
179 } else {
180 // Windows
181 return dirs::data_local_dir()
182 .expect("failed to determine LocalAppData directory")
183 .join(app_name());
184 }
185 })
186}
187
188/// Returns the path to the temp directory used by Zed.
189pub fn temp_dir() -> &'static PathBuf {
190 static TEMP_DIR: OnceLock<PathBuf> = OnceLock::new();
191 TEMP_DIR.get_or_init(|| {
192 if let Some(custom_dir) = CUSTOM_DATA_DIR.get() {
193 return custom_dir.join("cache");
194 }
195
196 if cfg!(target_os = "macos") {
197 return dirs::cache_dir()
198 .expect("failed to determine cachesDirectory directory")
199 .join(app_storage_slug());
200 }
201
202 if cfg!(target_os = "windows") {
203 return dirs::cache_dir()
204 .expect("failed to determine LocalAppData directory")
205 .join(app_storage_slug());
206 }
207
208 if cfg!(any(target_os = "linux", target_os = "freebsd")) {
209 return if let Ok(flatpak_xdg_cache) = std::env::var("FLATPAK_XDG_CACHE_HOME") {
210 flatpak_xdg_cache.into()
211 } else {
212 dirs::cache_dir().expect("failed to determine XDG_CACHE_HOME directory")
213 }
214 .join(app_storage_slug());
215 }
216
217 home_dir().join(".cache").join(app_storage_slug())
218 })
219}
220
221/// Returns the path to the hang traces directory.
222pub fn hang_traces_dir() -> &'static PathBuf {
223 static LOGS_DIR: OnceLock<PathBuf> = OnceLock::new();
224 LOGS_DIR.get_or_init(|| data_dir().join("hang_traces"))
225}
226
227/// Returns the path to the logs directory.
228pub fn logs_dir() -> &'static PathBuf {
229 static LOGS_DIR: OnceLock<PathBuf> = OnceLock::new();
230 LOGS_DIR.get_or_init(|| {
231 if let Some(custom_dir) = CUSTOM_DATA_DIR.get() {
232 custom_dir.join("logs")
233 } else if cfg!(target_os = "macos") {
234 home_dir().join("Library/Logs").join(app_storage_slug())
235 } else {
236 data_dir().join("logs")
237 }
238 })
239}
240
241/// Returns the path to the Zed server directory on this SSH host.
242pub fn remote_server_state_dir() -> &'static PathBuf {
243 static REMOTE_SERVER_STATE: OnceLock<PathBuf> = OnceLock::new();
244 REMOTE_SERVER_STATE.get_or_init(|| data_dir().join("server_state"))
245}
246
247/// Returns the path to the current channel's log file.
248pub fn log_file() -> &'static PathBuf {
249 static LOG_FILE: OnceLock<PathBuf> = OnceLock::new();
250 LOG_FILE.get_or_init(|| logs_dir().join(format!("{}.log", app_storage_slug())))
251}
252
253/// Returns the path to the current channel's previous log file.
254pub fn old_log_file() -> &'static PathBuf {
255 static OLD_LOG_FILE: OnceLock<PathBuf> = OnceLock::new();
256 OLD_LOG_FILE.get_or_init(|| logs_dir().join(format!("{}.log.old", app_storage_slug())))
257}
258
259/// Returns the path to the database directory.
260pub fn database_dir() -> &'static PathBuf {
261 static DATABASE_DIR: OnceLock<PathBuf> = OnceLock::new();
262 DATABASE_DIR.get_or_init(|| data_dir().join("db"))
263}
264
265/// Returns the path to the crashes directory, if it exists for the current platform.
266pub fn crashes_dir() -> &'static Option<PathBuf> {
267 static CRASHES_DIR: OnceLock<Option<PathBuf>> = OnceLock::new();
268 CRASHES_DIR.get_or_init(|| {
269 cfg!(target_os = "macos").then_some(home_dir().join("Library/Logs/DiagnosticReports"))
270 })
271}
272
273/// Returns the path to the retired crashes directory, if it exists for the current platform.
274pub fn crashes_retired_dir() -> &'static Option<PathBuf> {
275 static CRASHES_RETIRED_DIR: OnceLock<Option<PathBuf>> = OnceLock::new();
276 CRASHES_RETIRED_DIR.get_or_init(|| crashes_dir().as_ref().map(|dir| dir.join("Retired")))
277}
278
279/// Returns the path to the `settings.json` file.
280pub fn settings_file() -> &'static PathBuf {
281 static SETTINGS_FILE: OnceLock<PathBuf> = OnceLock::new();
282 SETTINGS_FILE.get_or_init(|| config_dir().join("settings.json"))
283}
284
285/// Returns the path to the global settings file.
286pub fn global_settings_file() -> &'static PathBuf {
287 static GLOBAL_SETTINGS_FILE: OnceLock<PathBuf> = OnceLock::new();
288 GLOBAL_SETTINGS_FILE.get_or_init(|| config_dir().join("global_settings.json"))
289}
290
291/// Returns the path to the `settings_backup.json` file.
292pub fn settings_backup_file() -> &'static PathBuf {
293 static SETTINGS_FILE: OnceLock<PathBuf> = OnceLock::new();
294 SETTINGS_FILE.get_or_init(|| config_dir().join("settings_backup.json"))
295}
296
297/// Returns the path to the `keymap.json` file.
298pub fn keymap_file() -> &'static PathBuf {
299 static KEYMAP_FILE: OnceLock<PathBuf> = OnceLock::new();
300 KEYMAP_FILE.get_or_init(|| config_dir().join("keymap.json"))
301}
302
303/// Returns the path to the `keymap_backup.json` file.
304pub fn keymap_backup_file() -> &'static PathBuf {
305 static KEYMAP_FILE: OnceLock<PathBuf> = OnceLock::new();
306 KEYMAP_FILE.get_or_init(|| config_dir().join("keymap_backup.json"))
307}
308
309/// Returns the path to the `tasks.json` file.
310pub fn tasks_file() -> &'static PathBuf {
311 static TASKS_FILE: OnceLock<PathBuf> = OnceLock::new();
312 TASKS_FILE.get_or_init(|| config_dir().join("tasks.json"))
313}
314
315/// Returns the path to the `debug.json` file.
316pub fn debug_scenarios_file() -> &'static PathBuf {
317 static DEBUG_SCENARIOS_FILE: OnceLock<PathBuf> = OnceLock::new();
318 DEBUG_SCENARIOS_FILE.get_or_init(|| config_dir().join("debug.json"))
319}
320
321/// Returns the path to the user-global `AGENTS.md` file.
322///
323/// This file holds personal agent instructions that apply to every project the
324/// user opens, and is loaded into Omega Agent's system prompt.
325pub fn agents_file() -> &'static PathBuf {
326 static AGENTS_FILE: OnceLock<PathBuf> = OnceLock::new();
327 AGENTS_FILE.get_or_init(|| config_dir().join("AGENTS.md"))
328}
329
330/// User-facing display form of the user-global `AGENTS.md` file path —
331/// i.e. what a human should see in messages and prompts, with the
332/// platform's native path separator and home/config directory shorthand.
333///
334/// Windows doesn't recognize `~` as the home directory, so the env-var
335/// form (`%APPDATA%`) is used there instead. Note that this is the
336/// *typical* location: a user with `XDG_CONFIG_HOME` set or running in a
337/// Flatpak sandbox would see a different `agents_file()` at runtime than
338/// this displays. The display string trades that precision for
339/// readability in announcement copy.
340pub fn global_agents_file_display() -> &'static str {
341 static DISPLAY: LazyLock<String> = LazyLock::new(|| {
342 if cfg!(target_os = "windows") {
343 format!("%APPDATA%\\{}\\AGENTS.md", app_name())
344 } else {
345 format!("~/.config/{}/AGENTS.md", app_storage_slug())
346 }
347 });
348 DISPLAY.as_str()
349}
350
351/// Returns the path to the extensions directory.
352///
353/// This is where installed extensions are stored.
354pub fn extensions_dir() -> &'static PathBuf {
355 static EXTENSIONS_DIR: OnceLock<PathBuf> = OnceLock::new();
356 EXTENSIONS_DIR.get_or_init(|| data_dir().join("extensions"))
357}
358
359/// Returns the path to the extensions directory.
360///
361/// This is where installed extensions are stored on a remote.
362pub fn remote_extensions_dir() -> &'static PathBuf {
363 static EXTENSIONS_DIR: OnceLock<PathBuf> = OnceLock::new();
364 EXTENSIONS_DIR.get_or_init(|| data_dir().join("remote_extensions"))
365}
366
367/// Returns the path to the extensions directory.
368///
369/// This is where installed extensions are stored on a remote.
370pub fn remote_extensions_uploads_dir() -> &'static PathBuf {
371 static UPLOAD_DIR: OnceLock<PathBuf> = OnceLock::new();
372 UPLOAD_DIR.get_or_init(|| remote_extensions_dir().join("uploads"))
373}
374
375/// Returns the path to the themes directory.
376///
377/// This is where themes that are not provided by extensions are stored.
378pub fn themes_dir() -> &'static PathBuf {
379 static THEMES_DIR: OnceLock<PathBuf> = OnceLock::new();
380 THEMES_DIR.get_or_init(|| config_dir().join("themes"))
381}
382
383/// Returns the path to the snippets directory.
384pub fn snippets_dir() -> &'static PathBuf {
385 static SNIPPETS_DIR: OnceLock<PathBuf> = OnceLock::new();
386 SNIPPETS_DIR.get_or_init(|| config_dir().join("snippets"))
387}
388
389/// Returns the path to the contexts directory.
390///
391/// This is where the prompts for use with the Assistant are stored.
392pub fn prompts_dir() -> &'static PathBuf {
393 static PROMPTS_DIR: OnceLock<PathBuf> = OnceLock::new();
394 PROMPTS_DIR.get_or_init(|| {
395 if cfg!(target_os = "macos") {
396 config_dir().join("prompts")
397 } else {
398 data_dir().join("prompts")
399 }
400 })
401}
402
403/// Returns the path to the prompt templates directory.
404///
405/// This is where the prompt templates for core features can be overridden with templates.
406///
407/// # Arguments
408///
409/// * `dev_mode` - If true, assumes the current working directory is the Zed repository.
410pub fn prompt_overrides_dir(repo_path: Option<&Path>) -> PathBuf {
411 if let Some(path) = repo_path {
412 let dev_path = path.join("assets").join("prompts");
413 if dev_path.exists() {
414 return dev_path;
415 }
416 }
417
418 static PROMPT_TEMPLATES_DIR: OnceLock<PathBuf> = OnceLock::new();
419 PROMPT_TEMPLATES_DIR
420 .get_or_init(|| {
421 if cfg!(target_os = "macos") {
422 config_dir().join("prompt_overrides")
423 } else {
424 data_dir().join("prompt_overrides")
425 }
426 })
427 .clone()
428}
429
430/// Returns the path to the semantic search's embeddings directory.
431///
432/// This is where the embeddings used to power semantic search are stored.
433pub fn embeddings_dir() -> &'static PathBuf {
434 static EMBEDDINGS_DIR: OnceLock<PathBuf> = OnceLock::new();
435 EMBEDDINGS_DIR.get_or_init(|| {
436 if cfg!(target_os = "macos") {
437 config_dir().join("embeddings")
438 } else {
439 data_dir().join("embeddings")
440 }
441 })
442}
443
444/// Returns the path to the languages directory.
445///
446/// This is where language servers are downloaded to for languages built-in to Zed.
447pub fn languages_dir() -> &'static PathBuf {
448 static LANGUAGES_DIR: OnceLock<PathBuf> = OnceLock::new();
449 LANGUAGES_DIR.get_or_init(|| data_dir().join("languages"))
450}
451
452/// Returns the path to the debug adapters directory
453///
454/// This is where debug adapters are downloaded to for DAPs that are built-in to Zed.
455pub fn debug_adapters_dir() -> &'static PathBuf {
456 static DEBUG_ADAPTERS_DIR: OnceLock<PathBuf> = OnceLock::new();
457 DEBUG_ADAPTERS_DIR.get_or_init(|| data_dir().join("debug_adapters"))
458}
459
460/// Returns the path to the external agents directory
461///
462/// This is where agent servers are downloaded to
463pub fn external_agents_dir() -> &'static PathBuf {
464 static EXTERNAL_AGENTS_DIR: OnceLock<PathBuf> = OnceLock::new();
465 EXTERNAL_AGENTS_DIR.get_or_init(|| data_dir().join("external_agents"))
466}
467
468/// Returns the path to the Copilot directory.
469pub fn copilot_dir() -> &'static PathBuf {
470 static COPILOT_DIR: OnceLock<PathBuf> = OnceLock::new();
471 COPILOT_DIR.get_or_init(|| data_dir().join("copilot"))
472}
473
474/// Returns the path to the default Prettier directory.
475pub fn default_prettier_dir() -> &'static PathBuf {
476 static DEFAULT_PRETTIER_DIR: OnceLock<PathBuf> = OnceLock::new();
477 DEFAULT_PRETTIER_DIR.get_or_init(|| data_dir().join("prettier"))
478}
479
480/// Returns the path to the remote server binaries directory.
481pub fn remote_servers_dir() -> &'static PathBuf {
482 static REMOTE_SERVERS_DIR: OnceLock<PathBuf> = OnceLock::new();
483 REMOTE_SERVERS_DIR.get_or_init(|| data_dir().join("remote_servers"))
484}
485
486/// Returns the path to the directory where the devcontainer CLI is installed.
487pub fn devcontainer_dir() -> &'static PathBuf {
488 static DEVCONTAINER_DIR: OnceLock<PathBuf> = OnceLock::new();
489 DEVCONTAINER_DIR.get_or_init(|| data_dir().join("devcontainer"))
490}
491
492/// Returns the relative path to a `.zed` folder within a project.
493pub fn local_settings_folder_name() -> &'static str {
494 ".zed"
495}
496
497/// Returns the relative path to a `.vscode` folder within a project.
498pub fn local_vscode_folder_name() -> &'static str {
499 ".vscode"
500}
501
502/// Returns the relative path to a `settings.json` file within a project.
503pub fn local_settings_file_relative_path() -> &'static RelPath {
504 static CACHED: LazyLock<&'static RelPath> =
505 LazyLock::new(|| RelPath::from_unix_str(".zed/settings.json").unwrap());
506 *CACHED
507}
508
509/// Returns the relative path to a `tasks.json` file within a project.
510pub fn local_tasks_file_relative_path() -> &'static RelPath {
511 static CACHED: LazyLock<&'static RelPath> =
512 LazyLock::new(|| RelPath::from_unix_str(".zed/tasks.json").unwrap());
513 *CACHED
514}
515
516/// Returns the relative path to a `.vscode/tasks.json` file within a project.
517pub fn local_vscode_tasks_file_relative_path() -> &'static RelPath {
518 static CACHED: LazyLock<&'static RelPath> =
519 LazyLock::new(|| RelPath::from_unix_str(".vscode/tasks.json").unwrap());
520 *CACHED
521}
522
523pub fn debug_task_file_name() -> &'static str {
524 "debug.json"
525}
526
527pub fn task_file_name() -> &'static str {
528 "tasks.json"
529}
530
531/// Returns the relative path to a `debug.json` file within a project.
532/// .zed/debug.json
533pub fn local_debug_file_relative_path() -> &'static RelPath {
534 static CACHED: LazyLock<&'static RelPath> =
535 LazyLock::new(|| RelPath::from_unix_str(".zed/debug.json").unwrap());
536 *CACHED
537}
538
539/// Returns the relative path to a `.vscode/launch.json` file within a project.
540pub fn local_vscode_launch_file_relative_path() -> &'static RelPath {
541 static CACHED: LazyLock<&'static RelPath> =
542 LazyLock::new(|| RelPath::from_unix_str(".vscode/launch.json").unwrap());
543 *CACHED
544}
545
546pub fn user_ssh_config_file() -> PathBuf {
547 home_dir().join(".ssh/config")
548}
549
550pub fn global_ssh_config_file() -> Option<&'static Path> {
551 if cfg!(windows) {
552 None
553 } else {
554 Some(Path::new("/etc/ssh/ssh_config"))
555 }
556}
557
558/// Returns candidate paths for the vscode user settings file
559pub fn vscode_settings_file_paths() -> Vec<PathBuf> {
560 let mut paths = vscode_user_data_paths();
561 for path in paths.iter_mut() {
562 path.push("User/settings.json");
563 }
564 paths
565}
566
567/// Returns candidate paths for the cursor user settings file
568pub fn cursor_settings_file_paths() -> Vec<PathBuf> {
569 let mut paths = cursor_user_data_paths();
570 for path in paths.iter_mut() {
571 path.push("User/settings.json");
572 }
573 paths
574}
575
576fn vscode_user_data_paths() -> Vec<PathBuf> {
577 // https://github.com/microsoft/vscode/blob/23e7148cdb6d8a27f0109ff77e5b1e019f8da051/src/vs/platform/environment/node/userDataPath.ts#L45
578 const VSCODE_PRODUCT_NAMES: &[&str] = &[
579 "Code",
580 "Code - Insiders",
581 "Code - OSS",
582 "VSCodium",
583 "VSCodium - Insiders",
584 "Code Dev",
585 "Code - OSS Dev",
586 "code-oss-dev",
587 ];
588 let mut paths = Vec::new();
589 if let Ok(portable_path) = env::var("VSCODE_PORTABLE") {
590 paths.push(Path::new(&portable_path).join("user-data"));
591 }
592 if let Ok(vscode_appdata) = env::var("VSCODE_APPDATA") {
593 for product_name in VSCODE_PRODUCT_NAMES {
594 paths.push(Path::new(&vscode_appdata).join(product_name));
595 }
596 }
597 for product_name in VSCODE_PRODUCT_NAMES {
598 add_vscode_user_data_paths(&mut paths, product_name);
599 }
600 paths
601}
602
603fn cursor_user_data_paths() -> Vec<PathBuf> {
604 let mut paths = Vec::new();
605 add_vscode_user_data_paths(&mut paths, "Cursor");
606 paths
607}
608
609fn add_vscode_user_data_paths(paths: &mut Vec<PathBuf>, product_name: &str) {
610 if cfg!(target_os = "macos") {
611 paths.push(
612 home_dir()
613 .join("Library/Application Support")
614 .join(product_name),
615 );
616 } else if cfg!(target_os = "windows") {
617 if let Some(data_local_dir) = dirs::data_local_dir() {
618 paths.push(data_local_dir.join(product_name));
619 }
620 if let Some(data_dir) = dirs::data_dir() {
621 paths.push(data_dir.join(product_name));
622 }
623 } else {
624 paths.push(
625 dirs::config_dir()
626 .unwrap_or(home_dir().join(".config"))
627 .join(product_name),
628 );
629 }
630}
631
632#[cfg(any(test, feature = "test-support"))]
633pub fn global_gitignore_path() -> Option<PathBuf> {
634 Some(home_dir().join(".config").join("git").join("ignore"))
635}
636
637#[cfg(not(any(test, feature = "test-support")))]
638pub fn global_gitignore_path() -> Option<PathBuf> {
639 static GLOBAL_GITIGNORE_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
640 GLOBAL_GITIGNORE_PATH
641 .get_or_init(::ignore::gitignore::gitconfig_excludes_path)
642 .clone()
643}
644
645#[cfg(test)]
646mod tests {
647 use super::*;
648
649 #[test]
650 fn default_roots_use_the_current_omega_channel() {
651 assert!(app_name().starts_with("Omega"));
652 assert!(app_storage_slug().starts_with("omega"));
653 assert_eq!(
654 config_dir().file_name().and_then(|name| name.to_str()),
655 Some(app_storage_slug())
656 );
657
658 if cfg!(any(target_os = "macos", target_os = "windows")) {
659 assert_eq!(
660 data_dir().file_name().and_then(|name| name.to_str()),
661 Some(app_name())
662 );
663 } else {
664 assert_eq!(
665 data_dir().file_name().and_then(|name| name.to_str()),
666 Some(app_storage_slug())
667 );
668 }
669
670 assert!(!log_file().to_string_lossy().to_lowercase().contains("zed"));
671 }
672}
673