Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add global `Fs` instance (#15044)
Marshall Bowersd36ebc8c7463
diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.tomlindex 98ce4657114..105b11b7757 100644--- a/crates/fs/Cargo.toml+++ b/crates/fs/Cargo.toml@@ -19,7 +19,7 @@ collections.workspace = truefutures.workspace = truegit.workspace = truegit2.workspace = true-gpui = { workspace = true, optional = true }+gpui.workspace = truelazy_static.workspace = truelibc.workspace = trueparking_lot.workspace = truediff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rsindex 6ee5f05148d..924fb9a2152 100644--- a/crates/fs/src/fs.rs+++ b/crates/fs/src/fs.rs@@ -12,6 +12,7 @@ use std::os::unix::fs::MetadataExt;use async_tar::Archive;use futures::{future::BoxFuture, AsyncRead, Stream, StreamExt};use git::repository::{GitRepository, RealGitRepository};+use gpui::{AppContext, Global, ReadGlobal};use rope::Rope;use smol::io::AsyncWriteExt;use std::{@@ -102,6 +103,22 @@ pub trait Fs: Send + Sync {}}+struct GlobalFs(Arc<dyn Fs>);++impl Global for GlobalFs {}++impl dyn Fs {+ /// Returns the global [`Fs`].+ pub fn global(cx: &AppContext) -> Arc<Self> {+ GlobalFs::global(cx).0.clone()+ }++ /// Sets the global [`Fs`].+ pub fn set_global(fs: Arc<Self>, cx: &mut AppContext) {+ cx.set_global(GlobalFs(fs));+ }+}+#[derive(Copy, Clone, Default)]pub struct CreateOptions {pub overwrite: bool,diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rsindex c9efc2a8d65..05321809272 100644--- a/crates/zed/src/main.rs+++ b/crates/zed/src/main.rs@@ -14,7 +14,7 @@ use collab_ui::channel_view::ChannelView;use db::kvp::KEY_VALUE_STORE;use editor::Editor;use env_logger::Builder;-use fs::RealFs;+use fs::{Fs, RealFs};use futures::{future, StreamExt};use git::GitHostingProviderRegistry;use gpui::{@@ -399,6 +399,8 @@ fn main() {AppCommitSha::set_global(AppCommitSha(build_sha.into()), cx);}+ <dyn Fs>::set_global(fs.clone(), cx);+GitHostingProviderRegistry::set_global(git_hosting_provider_registry, cx);git_hosting_providers::init(cx);