mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
gpui: Reduce amount of wasm cfgs in gpui (#50278)
Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
parent
7e582468db
commit
7f09bff76a
12 changed files with 19 additions and 45 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -14242,13 +14242,13 @@ dependencies = [
|
|||
"bytes 1.11.1",
|
||||
"futures 0.3.31",
|
||||
"gpui",
|
||||
"gpui_util",
|
||||
"http_client",
|
||||
"http_client_tls",
|
||||
"log",
|
||||
"regex",
|
||||
"serde",
|
||||
"tokio",
|
||||
"util",
|
||||
"zed-reqwest",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ etagere = "0.2"
|
|||
futures.workspace = true
|
||||
futures-concurrency.workspace = true
|
||||
gpui_macros.workspace = true
|
||||
http_client.workspace = true
|
||||
image.workspace = true
|
||||
inventory.workspace = true
|
||||
itertools.workspace = true
|
||||
|
|
@ -103,8 +104,6 @@ web-time.workspace = true
|
|||
getrandom = { version = "0.3.4", features = ["wasm_js"] }
|
||||
uuid = { workspace = true, features = ["js"] }
|
||||
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
http_client.workspace = true
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
block = "0.1"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ use collections::{FxHashMap, FxHashSet, HashMap, VecDeque};
|
|||
pub use context::*;
|
||||
pub use entity_map::*;
|
||||
use gpui_util::{ResultExt, debug_panic};
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use http_client::{HttpClient, Url};
|
||||
use smallvec::SmallVec;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
|
|
@ -139,7 +138,6 @@ impl Application {
|
|||
Self(App::new_app(
|
||||
platform,
|
||||
Arc::new(()),
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
Arc::new(NullHttpClient),
|
||||
))
|
||||
}
|
||||
|
|
@ -155,7 +153,6 @@ impl Application {
|
|||
}
|
||||
|
||||
/// Sets the HTTP client for the application.
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn with_http_client(self, http_client: Arc<dyn HttpClient>) -> Self {
|
||||
let mut context_lock = self.0.borrow_mut();
|
||||
context_lock.http_client = http_client;
|
||||
|
|
@ -585,7 +582,6 @@ pub struct App {
|
|||
pub(crate) loading_assets: FxHashMap<(TypeId, u64), Box<dyn Any>>,
|
||||
asset_source: Arc<dyn AssetSource>,
|
||||
pub(crate) svg_renderer: SvgRenderer,
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
pub(crate) globals_by_type: FxHashMap<TypeId, Box<dyn Any>>,
|
||||
pub(crate) entities: EntityMap,
|
||||
|
|
@ -642,7 +638,7 @@ impl App {
|
|||
pub(crate) fn new_app(
|
||||
platform: Rc<dyn Platform>,
|
||||
asset_source: Arc<dyn AssetSource>,
|
||||
#[cfg(not(target_family = "wasm"))] http_client: Arc<dyn HttpClient>,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
) -> Rc<AppCell> {
|
||||
let background_executor = platform.background_executor();
|
||||
let foreground_executor = platform.foreground_executor();
|
||||
|
|
@ -672,7 +668,6 @@ impl App {
|
|||
svg_renderer: SvgRenderer::new(asset_source.clone()),
|
||||
loading_assets: Default::default(),
|
||||
asset_source,
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
http_client,
|
||||
globals_by_type: FxHashMap::default(),
|
||||
entities,
|
||||
|
|
@ -1281,13 +1276,11 @@ impl App {
|
|||
}
|
||||
|
||||
/// Returns the HTTP client for the application.
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn http_client(&self) -> Arc<dyn HttpClient> {
|
||||
self.http_client.clone()
|
||||
}
|
||||
|
||||
/// Sets the HTTP client for the application.
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn set_http_client(&mut self, new_client: Arc<dyn HttpClient>) {
|
||||
self.http_client = new_client;
|
||||
}
|
||||
|
|
@ -2512,10 +2505,8 @@ pub struct KeystrokeEvent {
|
|||
pub context_stack: Vec<KeyContext>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
struct NullHttpClient;
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
impl HttpClient for NullHttpClient {
|
||||
fn send(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -120,16 +120,10 @@ impl TestAppContext {
|
|||
let foreground_executor = ForegroundExecutor::new(arc_dispatcher);
|
||||
let platform = TestPlatform::new(background_executor.clone(), foreground_executor.clone());
|
||||
let asset_source = Arc::new(());
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
let http_client = http_client::FakeHttpClient::with_404_response();
|
||||
let text_system = Arc::new(TextSystem::new(platform.text_system()));
|
||||
|
||||
let app = App::new_app(
|
||||
platform.clone(),
|
||||
asset_source,
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
http_client,
|
||||
);
|
||||
let app = App::new_app(platform.clone(), asset_source, http_client);
|
||||
app.borrow_mut().mode = GpuiMode::test();
|
||||
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -594,7 +594,6 @@ impl Asset for ImageAssetLoader {
|
|||
source: Self::Source,
|
||||
cx: &mut App,
|
||||
) -> impl Future<Output = Self::Output> + Send + 'static {
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
let client = cx.http_client();
|
||||
// TODO: Can we make SVGs always rescale?
|
||||
// let scale_factor = cx.scale_factor();
|
||||
|
|
@ -603,7 +602,6 @@ impl Asset for ImageAssetLoader {
|
|||
async move {
|
||||
let bytes = match source.clone() {
|
||||
Resource::Path(uri) => fs::read(uri.as_ref())?,
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
Resource::Uri(uri) => {
|
||||
use anyhow::Context as _;
|
||||
use futures::AsyncReadExt as _;
|
||||
|
|
@ -626,12 +624,6 @@ impl Asset for ImageAssetLoader {
|
|||
}
|
||||
body
|
||||
}
|
||||
#[cfg(target_family = "wasm")]
|
||||
Resource::Uri(_) => {
|
||||
return Err(ImageCacheError::Other(Arc::new(anyhow::anyhow!(
|
||||
"Uri resources are not supported on wasm"
|
||||
))));
|
||||
}
|
||||
Resource::Embedded(path) => {
|
||||
let data = asset_source.load(&path).ok().flatten();
|
||||
if let Some(data) = data {
|
||||
|
|
@ -722,7 +714,6 @@ pub enum ImageCacheError {
|
|||
#[error("IO error: {0}")]
|
||||
Io(Arc<std::io::Error>),
|
||||
/// An error that occurred while processing an image.
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
#[error("unexpected http status for {uri}: {status}, body: {body}")]
|
||||
BadStatus {
|
||||
/// The URI of the image.
|
||||
|
|
|
|||
|
|
@ -564,15 +564,9 @@ mod test {
|
|||
|
||||
let platform = TestPlatform::new(background_executor.clone(), foreground_executor);
|
||||
let asset_source = Arc::new(());
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
let http_client = http_client::FakeHttpClient::with_404_response();
|
||||
|
||||
let app = App::new_app(
|
||||
platform,
|
||||
asset_source,
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
http_client,
|
||||
);
|
||||
let app = App::new_app(platform, asset_source, http_client);
|
||||
(dispatcher, background_executor, app)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ pub use geometry::*;
|
|||
pub use global::*;
|
||||
pub use gpui_macros::{AppContext, IntoElement, Render, VisualContext, register_action, test};
|
||||
pub use gpui_util::arc_cow::ArcCow;
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub use http_client;
|
||||
pub use input::*;
|
||||
pub use inspector::*;
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ pub trait Platform: 'static {
|
|||
}
|
||||
|
||||
/// A handle to a platform's display, e.g. a monitor or laptop screen.
|
||||
pub trait PlatformDisplay: Send + Sync + Debug {
|
||||
pub trait PlatformDisplay: Debug {
|
||||
/// Get the ID for this display
|
||||
fn id(&self) -> DisplayId;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ doctest = true
|
|||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
async-compression.workspace = true
|
||||
async-fs.workspace = true
|
||||
async-tar.workspace = true
|
||||
bytes.workspace = true
|
||||
derive_more.workspace = true
|
||||
futures.workspace = true
|
||||
|
|
@ -31,7 +29,11 @@ parking_lot.workspace = true
|
|||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde_urlencoded.workspace = true
|
||||
url.workspace = true
|
||||
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
util.workspace = true
|
||||
async-fs.workspace = true
|
||||
async-tar.workspace = true
|
||||
sha2.workspace = true
|
||||
tempfile.workspace = true
|
||||
url.workspace = true
|
||||
util.workspace = true
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
mod async_body;
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub mod github;
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub mod github_download;
|
||||
|
||||
pub use anyhow::{Result, anyhow};
|
||||
|
|
|
|||
|
|
@ -20,13 +20,15 @@ anyhow.workspace = true
|
|||
bytes.workspace = true
|
||||
futures.workspace = true
|
||||
http_client.workspace = true
|
||||
http_client_tls.workspace = true
|
||||
serde.workspace = true
|
||||
log.workspace = true
|
||||
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
|
||||
regex.workspace = true
|
||||
reqwest.workspace = true
|
||||
util.workspace = true
|
||||
gpui_util.workspace = true
|
||||
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
http_client_tls.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
gpui.workspace = true
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::error::Error;
|
|||
use std::sync::{LazyLock, OnceLock};
|
||||
use std::{borrow::Cow, mem, pin::Pin, task::Poll, time::Duration};
|
||||
|
||||
use util::defer;
|
||||
use gpui_util::defer;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
|
|
|
|||
Loading…
Reference in a new issue