Add global Fs instance (#15044)
This PR adds a global `Fs` instance to the app context. This will make it easier to access the filesystem in some cases instead of having to thread it around. Release Notes: - N/A
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user