diff --git a/Cargo.lock b/Cargo.lock index 239323517c01045b3ddb0d23b1d99f0904d137a6..1e237d8438f319348a1408c5b82d74360ace09a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,6 +190,7 @@ dependencies = [ "uuid", "workspace", "workspace-hack", + "zed_env_vars", "zstd", ] @@ -278,6 +279,7 @@ dependencies = [ "web_search", "workspace-hack", "worktree", + "zed_env_vars", "zlog", "zstd", ] @@ -848,6 +850,7 @@ dependencies = [ "uuid", "workspace", "workspace-hack", + "zed_env_vars", ] [[package]] @@ -4489,6 +4492,7 @@ dependencies = [ "tempfile", "util", "workspace-hack", + "zed_env_vars", ] [[package]] @@ -20549,6 +20553,7 @@ dependencies = [ "workspace", "workspace-hack", "zed_actions", + "zed_env_vars", "zeta", "zlog", "zlog_settings", @@ -20565,6 +20570,13 @@ dependencies = [ "workspace-hack", ] +[[package]] +name = "zed_env_vars" +version = "0.1.0" +dependencies = [ + "workspace-hack", +] + [[package]] name = "zed_extension_api" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 08551ef75a315563f9cdb22c0ed92742d550df61..3e90af94c56aa7035dc82c1222d2152a6a8e09f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -193,6 +193,7 @@ members = [ "crates/x_ai", "crates/zed", "crates/zed_actions", + "crates/zed_env_vars", "crates/zeta", "crates/zeta_cli", "crates/zlog", @@ -420,6 +421,7 @@ worktree = { path = "crates/worktree" } x_ai = { path = "crates/x_ai" } zed = { path = "crates/zed" } zed_actions = { path = "crates/zed_actions" } +zed_env_vars = { path = "crates/zed_env_vars" } zeta = { path = "crates/zeta" } zlog = { path = "crates/zlog" } zlog_settings = { path = "crates/zlog_settings" } diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.toml index 391abb38fe826923b06646511c0dd6c5ce5c6ca4..76f96647c7af5692ca9b4b146e27f9f7c19c7995 100644 --- a/crates/agent/Cargo.toml +++ b/crates/agent/Cargo.toml @@ -63,6 +63,7 @@ time.workspace = true util.workspace = true uuid.workspace = true workspace-hack.workspace = true +zed_env_vars.workspace = true zstd.workspace = true [dev-dependencies] diff --git a/crates/agent/src/thread_store.rs b/crates/agent/src/thread_store.rs index cba2457566709d5664270a8239495aaac3fec6fb..2eae758b835d5d79ccf86f18be032f2d9bb87c2b 100644 --- a/crates/agent/src/thread_store.rs +++ b/crates/agent/src/thread_store.rs @@ -41,8 +41,7 @@ use std::{ }; use util::ResultExt as _; -pub static ZED_STATELESS: std::sync::LazyLock = - std::sync::LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty())); +use zed_env_vars::ZED_STATELESS; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum DataType { diff --git a/crates/agent2/Cargo.toml b/crates/agent2/Cargo.toml index 0e9c8fcf7237627d2cb7b17b977b68322160e6d5..b712bed258dfb69ddf81a1ba431ec7a3566b9baf 100644 --- a/crates/agent2/Cargo.toml +++ b/crates/agent2/Cargo.toml @@ -68,6 +68,7 @@ uuid.workspace = true watch.workspace = true web_search.workspace = true workspace-hack.workspace = true +zed_env_vars.workspace = true zstd.workspace = true [dev-dependencies] diff --git a/crates/agent2/src/db.rs b/crates/agent2/src/db.rs index e7d31c0c7ac4dd2327931e2d888ec29f6ca96e73..c78725138ffa081cc5b75c883d883b7a155d482c 100644 --- a/crates/agent2/src/db.rs +++ b/crates/agent2/src/db.rs @@ -18,6 +18,7 @@ use sqlez::{ }; use std::sync::Arc; use ui::{App, SharedString}; +use zed_env_vars::ZED_STATELESS; pub type DbMessage = crate::Message; pub type DbSummary = DetailedSummaryState; @@ -201,9 +202,6 @@ impl DbThread { } } -pub static ZED_STATELESS: std::sync::LazyLock = - std::sync::LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty())); - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum DataType { #[serde(rename = "json")] diff --git a/crates/assistant_context/Cargo.toml b/crates/assistant_context/Cargo.toml index 45c0072418782909829ba3186138f0c6a9456654..3e2761a84674c6c4201165edf856b675843315d9 100644 --- a/crates/assistant_context/Cargo.toml +++ b/crates/assistant_context/Cargo.toml @@ -50,8 +50,9 @@ text.workspace = true ui.workspace = true util.workspace = true uuid.workspace = true -workspace-hack.workspace = true workspace.workspace = true +workspace-hack.workspace = true +zed_env_vars.workspace = true [dev-dependencies] indoc.workspace = true diff --git a/crates/assistant_context/src/context_store.rs b/crates/assistant_context/src/context_store.rs index 6960d9db7948e8f09ea65ede91702d98e6bc99be..5fac44e31f4cc073af8fe6bbb57f75fc03b27f45 100644 --- a/crates/assistant_context/src/context_store.rs +++ b/crates/assistant_context/src/context_store.rs @@ -24,6 +24,7 @@ use rpc::AnyProtoClient; use std::sync::LazyLock; use std::{cmp::Reverse, ffi::OsStr, mem, path::Path, sync::Arc, time::Duration}; use util::{ResultExt, TryFutureExt}; +use zed_env_vars::ZED_STATELESS; pub(crate) fn init(client: &AnyProtoClient) { client.add_entity_message_handler(ContextStore::handle_advertise_contexts); @@ -788,8 +789,6 @@ impl ContextStore { fn reload(&mut self, cx: &mut Context) -> Task> { let fs = self.fs.clone(); cx.spawn(async move |this, cx| { - pub static ZED_STATELESS: LazyLock = - LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty())); if *ZED_STATELESS { return Ok(()); } diff --git a/crates/db/Cargo.toml b/crates/db/Cargo.toml index c53b2988b94dd5b355e132024c2677b61a83d071..de449cd38f77d062eda906cced3e3b697a370d15 100644 --- a/crates/db/Cargo.toml +++ b/crates/db/Cargo.toml @@ -27,6 +27,7 @@ sqlez.workspace = true sqlez_macros.workspace = true util.workspace = true workspace-hack.workspace = true +zed_env_vars.workspace = true [dev-dependencies] gpui = { workspace = true, features = ["test-support"] } diff --git a/crates/db/src/db.rs b/crates/db/src/db.rs index 0802bd8bb7ec738b948d0dbf14c24863833e3ba1..eab2f115d8e5c3db51541544a8dbc95f34713741 100644 --- a/crates/db/src/db.rs +++ b/crates/db/src/db.rs @@ -17,9 +17,10 @@ use sqlez::thread_safe_connection::ThreadSafeConnection; use sqlez_macros::sql; use std::future::Future; use std::path::Path; +use std::sync::atomic::AtomicBool; use std::sync::{LazyLock, atomic::Ordering}; -use std::{env, sync::atomic::AtomicBool}; use util::{ResultExt, maybe}; +use zed_env_vars::ZED_STATELESS; const CONNECTION_INITIALIZE_QUERY: &str = sql!( PRAGMA foreign_keys=TRUE; @@ -36,9 +37,6 @@ const FALLBACK_DB_NAME: &str = "FALLBACK_MEMORY_DB"; const DB_FILE_NAME: &str = "db.sqlite"; -pub static ZED_STATELESS: LazyLock = - LazyLock::new(|| env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty())); - pub static ALL_FILE_DB_FAILED: LazyLock = LazyLock::new(|| AtomicBool::new(false)); /// Open or create a database at the given directory path. diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 9aceec1fbebefd2cd87f83a8546064f376d198b1..f2295d5fa732d9e36e2b37cf346199f35cabc803 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -165,6 +165,7 @@ web_search_providers.workspace = true workspace-hack.workspace = true workspace.workspace = true zed_actions.workspace = true +zed_env_vars.workspace = true zeta.workspace = true zlog.workspace = true zlog_settings.workspace = true diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 52e475edf8620a1ce97ce732f12777d9bb0cad1a..9582e7a2ab541243a768370eb08ed1f4f1c465a3 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -288,7 +288,7 @@ pub fn main() { let (open_listener, mut open_rx) = OpenListener::new(); - let failed_single_instance_check = if *db::ZED_STATELESS + let failed_single_instance_check = if *zed_env_vars::ZED_STATELESS || *release_channel::RELEASE_CHANNEL == ReleaseChannel::Dev { false diff --git a/crates/zed_env_vars/Cargo.toml b/crates/zed_env_vars/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..9abfc410e7e74774c4e9e7608e8c1c3824ebc3c1 --- /dev/null +++ b/crates/zed_env_vars/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "zed_env_vars" +version = "0.1.0" +edition.workspace = true +publish.workspace = true +license = "GPL-3.0-or-later" + +[lints] +workspace = true + +[lib] +path = "src/zed_env_vars.rs" + +[features] +default = [] + +[dependencies] +workspace-hack.workspace = true diff --git a/crates/zed_env_vars/LICENSE-GPL b/crates/zed_env_vars/LICENSE-GPL new file mode 120000 index 0000000000000000000000000000000000000000..89e542f750cd3860a0598eff0dc34b56d7336dc4 --- /dev/null +++ b/crates/zed_env_vars/LICENSE-GPL @@ -0,0 +1 @@ +../../LICENSE-GPL \ No newline at end of file diff --git a/crates/zed_env_vars/src/zed_env_vars.rs b/crates/zed_env_vars/src/zed_env_vars.rs new file mode 100644 index 0000000000000000000000000000000000000000..d1679a0518f2bae857364b0035b6184350ffca55 --- /dev/null +++ b/crates/zed_env_vars/src/zed_env_vars.rs @@ -0,0 +1,6 @@ +use std::sync::LazyLock; + +/// Whether Zed is running in stateless mode. +/// When true, Zed will use in-memory databases instead of persistent storage. +pub static ZED_STATELESS: LazyLock = + LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty())); diff --git a/script/new-crate b/script/new-crate index 52ee900b30837cbf77fa1e3145e0282fa5e19b7c..1ac2d9262133c788969fe594b5b06480f1293fa7 100755 --- a/script/new-crate +++ b/script/new-crate @@ -63,6 +63,7 @@ anyhow.workspace = true gpui.workspace = true ui.workspace = true util.workspace = true +workspace-hack.workspace = true # Uncomment other workspace dependencies as needed # assistant.workspace = true