diff --git a/Cargo.lock b/Cargo.lock index 3e28404fc1..691ef73b1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,6 +609,7 @@ dependencies = [ "tempdir", "theme", "util", + "util_http", "workspace", ] @@ -1230,6 +1231,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap 3.2.25", + "cli_rpc", "core-foundation", "core-services", "dirs 3.0.2", @@ -1240,6 +1242,15 @@ dependencies = [ "util", ] +[[package]] +name = "cli_rpc" +version = "0.1.0" +dependencies = [ + "ipc-channel", + "serde", + "serde_derive", +] + [[package]] name = "client" version = "0.1.0" @@ -1271,6 +1282,7 @@ dependencies = [ "tiny_http", "url", "util", + "util_http", "uuid 1.3.2", ] @@ -1510,6 +1522,7 @@ dependencies = [ "smol", "theme", "util", + "util_http", ] [[package]] @@ -1855,7 +1868,6 @@ checksum = "14d05c10f541ae6f3bc5b3d923c20001f47db7d5f0b2bc6ad16490133842db79" dependencies = [ "cc", "libc", - "libnghttp2-sys", "libz-sys", "openssl-sys", "pkg-config", @@ -2885,20 +2897,12 @@ dependencies = [ "anyhow", "async-task", "backtrace", - "bindgen", - "block", - "cc", - "cocoa", "collections", - "core-foundation", - "core-graphics", - "core-text", "ctor", "dhat", "env_logger 0.9.3", "etagere", "font-kit", - "foreign-types", "futures 0.3.28", "gpui_macros", "image", @@ -2906,9 +2910,7 @@ dependencies = [ "lazy_static", "log", "media", - "metal", "num_cpus", - "objc", "ordered-float", "parking", "parking_lot 0.11.2", @@ -2936,6 +2938,41 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "gpui_mac" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-task", + "bindgen", + "block", + "cc", + "cocoa", + "collections", + "core-foundation", + "core-graphics", + "core-text", + "ctor", + "etagere", + "font-kit", + "foreign-types", + "gpui", + "log", + "media", + "metal", + "objc", + "ordered-float", + "parking_lot 0.11.2", + "pathfinder_geometry", + "postage", + "resvg", + "smol", + "time 0.3.21", + "tiny-skia", + "usvg", + "uuid 1.3.2", +] + [[package]] name = "gpui_macros" version = "0.1.0" @@ -3594,6 +3631,7 @@ dependencies = [ "unicase", "unindent", "util", + "util_http", ] [[package]] @@ -3691,16 +3729,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" -[[package]] -name = "libnghttp2-sys" -version = "0.1.7+1.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ed28aba195b38d5ff02b9170cbff627e336a20925e43b4945390401c5dc93f" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "libsqlite3-sys" version = "0.24.2" @@ -4241,6 +4269,7 @@ dependencies = [ "serde_json", "smol", "util", + "util_http", ] [[package]] @@ -5011,6 +5040,7 @@ dependencies = [ "toml", "unindent", "util", + "util_http", ] [[package]] @@ -7898,7 +7928,6 @@ dependencies = [ "dirs 3.0.2", "futures 0.3.28", "git2", - "isahc", "lazy_static", "log", "rand 0.8.5", @@ -7908,6 +7937,20 @@ dependencies = [ "smol", "take-until", "tempdir", +] + +[[package]] +name = "util_http" +version = "0.1.0" +dependencies = [ + "anyhow", + "futures 0.3.28", + "isahc", + "log", + "serde", + "serde_json", + "smol", + "tempdir", "url", ] @@ -8919,7 +8962,7 @@ dependencies = [ "breadcrumbs", "call", "chrono", - "cli", + "cli_rpc", "client", "clock", "collab_ui", @@ -8941,6 +8984,7 @@ dependencies = [ "fuzzy", "go_to_line", "gpui", + "gpui_mac", "ignore", "image", "indexmap", @@ -9011,6 +9055,7 @@ dependencies = [ "url", "urlencoding", "util", + "util_http", "uuid 1.3.2", "vim", "welcome", diff --git a/Cargo.toml b/Cargo.toml index 640384a792..7edb88d384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "crates/breadcrumbs", "crates/call", "crates/cli", + "crates/cli_rpc", "crates/client", "crates/clock", "crates/collab", @@ -27,6 +28,7 @@ members = [ "crates/git", "crates/go_to_line", "crates/gpui", + "crates/gpui_mac", "crates/gpui_macros", "crates/install_cli", "crates/journal", @@ -62,6 +64,7 @@ members = [ "crates/theme", "crates/theme_selector", "crates/util", + "crates/util_http", "crates/vim", "crates/workspace", "crates/welcome", @@ -79,7 +82,7 @@ env_logger = { version = "0.9" } futures = { version = "0.3" } globset = { version = "0.4" } indoc = "1" -isahc = "1.7.2" +isahc = {version = "1.7.2", default-features = false, features = ["text-decoding"]} lazy_static = { version = "1.4.0" } log = { version = "0.4.16", features = ["kv_unstable_serde"] } ordered-float = { version = "2.1.1" } diff --git a/crates/auto_update/Cargo.toml b/crates/auto_update/Cargo.toml index 884ed2b7a0..b348420c6c 100644 --- a/crates/auto_update/Cargo.toml +++ b/crates/auto_update/Cargo.toml @@ -18,6 +18,7 @@ settings = { path = "../settings" } theme = { path = "../theme" } workspace = { path = "../workspace" } util = { path = "../util" } +util_http = { path = "../util_http" } anyhow.workspace = true isahc.workspace = true lazy_static.workspace = true diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index 822886b580..228e3c13d3 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -15,7 +15,7 @@ use smol::{fs::File, io::AsyncReadExt, process::Command}; use std::{ffi::OsString, sync::Arc, time::Duration}; use update_notification::UpdateNotification; use util::channel::ReleaseChannel; -use util::http::HttpClient; +use util_http::HttpClient; use workspace::Workspace; const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification"; diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 2b4a375a5b..624ba4c91a 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -4,9 +4,6 @@ version = "0.1.0" edition = "2021" publish = false -[lib] -path = "src/cli.rs" -doctest = false [[bin]] name = "cli" @@ -20,6 +17,7 @@ ipc-channel = "0.16" serde.workspace = true serde_derive.workspace = true util = { path = "../util" } +cli_rpc = {path = "../cli_rpc"} [target.'cfg(target_os = "macos")'.dependencies] core-foundation = "0.9" diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index bdf677512c..d711c7f66e 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Context, Result}; use clap::Parser; -use cli::{CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME}; +use cli_rpc::{CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME}; use core_foundation::{ array::{CFArray, CFIndex}, string::kCFStringEncodingUTF8, diff --git a/crates/cli_rpc/Cargo.toml b/crates/cli_rpc/Cargo.toml new file mode 100644 index 0000000000..38d94da89c --- /dev/null +++ b/crates/cli_rpc/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "cli_rpc" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ipc-channel = "0.16" +serde.workspace = true +serde_derive.workspace = true diff --git a/crates/cli/src/cli.rs b/crates/cli_rpc/src/lib.rs similarity index 100% rename from crates/cli/src/cli.rs rename to crates/cli_rpc/src/lib.rs diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 3ecc515986..23b1ea2083 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -16,6 +16,7 @@ collections = { path = "../collections" } db = { path = "../db" } gpui = { path = "../gpui" } util = { path = "../util" } +util_http = { path = "../util_http" } rpc = { path = "../rpc" } settings = { path = "../settings" } staff_mode = { path = "../staff_mode" } diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 78bcc55e93..df7ee00702 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -41,7 +41,7 @@ use telemetry::Telemetry; use thiserror::Error; use url::Url; use util::channel::ReleaseChannel; -use util::http::HttpClient; +use util_http::HttpClient; use util::{ResultExt, TryFutureExt}; pub use rpc::*; @@ -141,7 +141,7 @@ pub enum EstablishConnectionError { #[error("{0}")] Other(#[from] anyhow::Error), #[error("{0}")] - Http(#[from] util::http::Error), + Http(#[from] util_http::Error), #[error("{0}")] Io(#[from] std::io::Error), #[error("{0}")] @@ -1416,7 +1416,7 @@ mod tests { use gpui::{executor::Deterministic, TestAppContext}; use parking_lot::Mutex; use std::future; - use util::http::FakeHttpClient; + use util_http::FakeHttpClient; #[gpui::test(iterations = 10)] async fn test_reconnection(cx: &mut TestAppContext) { diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 6a6a91b485..6ee57a4ee6 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -6,7 +6,7 @@ use parking_lot::Mutex; use serde::Serialize; use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration}; use tempfile::NamedTempFile; -use util::http::HttpClient; +use util_http::HttpClient; use util::{channel::ReleaseChannel, TryFutureExt}; use uuid::Uuid; diff --git a/crates/client/src/test.rs b/crates/client/src/test.rs index 4c12a20566..12aa61c7bc 100644 --- a/crates/client/src/test.rs +++ b/crates/client/src/test.rs @@ -8,7 +8,7 @@ use rpc::{ ConnectionId, Peer, Receipt, TypedEnvelope, }; use std::{rc::Rc, sync::Arc}; -use util::http::FakeHttpClient; +use util_http::FakeHttpClient; pub struct FakeServer { peer: Arc, diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index 4c2721ffeb..d289f80fa5 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -7,7 +7,7 @@ use postage::{sink::Sink, watch}; use rpc::proto::{RequestMessage, UsersResponse}; use staff_mode::StaffMode; use std::sync::{Arc, Weak}; -use util::http::HttpClient; +use util_http::HttpClient; use util::TryFutureExt as _; #[derive(Default, Debug)] diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.toml index bac335f7b7..004c0c9fb3 100644 --- a/crates/copilot/Cargo.toml +++ b/crates/copilot/Cargo.toml @@ -28,6 +28,7 @@ theme = { path = "../theme" } lsp = { path = "../lsp" } node_runtime = { path = "../node_runtime"} util = { path = "../util" } +util_http = { path = "../util_http" } async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] } async-tar = "0.4.2" anyhow.workspace = true diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index e73424f0cd..d792b2827a 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -29,8 +29,9 @@ use std::{ sync::Arc, }; use util::{ - fs::remove_matching, github::latest_github_release, http::HttpClient, paths, ResultExt, + fs::remove_matching, paths, ResultExt, }; +use util_http::{HttpClient, github::latest_github_release}; const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth"; actions!(copilot_auth, [SignIn, SignOut]); diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 31b7db008d..d39c5b1c86 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -14,6 +14,7 @@ doctest = false test-support = ["backtrace", "dhat", "env_logger", "collections/test-support"] [dependencies] +anyhow.workspace = true collections = { path = "../collections" } gpui_macros = { path = "../gpui_macros" } util = { path = "../util" } @@ -52,10 +53,6 @@ usvg = { version = "0.14", features = [] } uuid = { version = "1.1.2", features = ["v4"] } waker-fn = "1.1.0" -[build-dependencies] -bindgen = "0.65.1" -cc = "1.0.67" - [dev-dependencies] backtrace = "0.3" collections = { path = "../collections", features = ["test-support"] } @@ -66,14 +63,4 @@ simplelog = "0.9" [target.'cfg(target_os = "macos")'.dependencies] media = { path = "../media" } -anyhow.workspace = true -block = "0.1" -cocoa = "0.24" -core-foundation = { version = "0.9.3", features = ["with-uuid"] } -core-graphics = "0.22.3" -core-text = "19.2" font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "b2f77d56f450338aa4f7dd2f0197d8c9acb0cf18" } -foreign-types = "0.3" -log.workspace = true -metal = "0.21.0" -objc = "0.2" diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 41684f3226..3662b23821 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -138,10 +138,12 @@ pub trait BorrowWindowContext { pub struct App(Rc>); impl App { - pub fn new(asset_source: impl AssetSource) -> Result { - let platform = platform::current::platform(); + pub fn new( + asset_source: impl AssetSource, + platform: Arc, + foreground_platform: Rc, + ) -> Result { let foreground = Rc::new(executor::Foreground::platform(platform.dispatcher())?); - let foreground_platform = platform::current::foreground_platform(foreground.clone()); let app = Self(Rc::new(RefCell::new(AppContext::new( foreground, Arc::new(executor::Background::new()), diff --git a/crates/gpui/src/clipboard.rs b/crates/gpui/src/clipboard.rs index b7e4b600ee..ceb2db9320 100644 --- a/crates/gpui/src/clipboard.rs +++ b/crates/gpui/src/clipboard.rs @@ -33,8 +33,11 @@ impl ClipboardItem { .as_ref() .and_then(|m| serde_json::from_str(m).ok()) } + pub fn raw_metadata(&self) -> Option<&str> { + self.metadata.as_deref() + } - pub(crate) fn text_hash(text: &str) -> u64 { + pub fn text_hash(text: &str) -> u64 { let mut hasher = SeaHasher::new(); text.hash(&mut hasher); hasher.finish() diff --git a/crates/gpui/src/gpui.rs b/crates/gpui/src/gpui.rs index a172667fb9..106ad0e349 100644 --- a/crates/gpui/src/gpui.rs +++ b/crates/gpui/src/gpui.rs @@ -1,8 +1,6 @@ mod app; pub use app::*; mod assets; -#[cfg(any(test, feature = "test-support"))] -pub mod test; pub use assets::*; pub mod elements; pub mod font_cache; diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 67f8e52c04..2980339035 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -1,11 +1,4 @@ mod event; -#[cfg(target_os = "macos")] -pub mod mac; -pub mod test; -pub mod current { - #[cfg(target_os = "macos")] - pub use super::mac::*; -} use crate::{ executor, @@ -87,7 +80,7 @@ pub trait Platform: Send + Sync { fn restart(&self); } -pub(crate) trait ForegroundPlatform { +pub trait ForegroundPlatform { fn on_become_active(&self, callback: Box); fn on_resign_active(&self, callback: Box); fn on_quit(&self, callback: Box); @@ -300,9 +293,9 @@ impl Default for CursorStyle { #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct AppVersion { - major: usize, - minor: usize, - patch: usize, + pub major: usize, + pub minor: usize, + pub patch: usize, } impl FromStr for AppVersion { diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rs index 7793a28ee0..a639f05412 100644 --- a/crates/gpui/src/scene.rs +++ b/crates/gpui/src/scene.rs @@ -13,7 +13,7 @@ use crate::{ fonts::{FontId, GlyphId}, geometry::{rect::RectF, vector::Vector2F}, json::ToJson, - platform::{current::Surface, CursorStyle}, + platform::CursorStyle, ImageData, }; pub use mouse_event::*; @@ -100,6 +100,11 @@ pub struct Icon { pub color: Color, } +pub struct Surface { + pub bounds: RectF, + pub image_buffer: media::core_video::CVImageBuffer, +} + #[derive(Clone, Copy, Default, Debug, JsonSchema)] pub struct Border { pub width: f32, diff --git a/crates/gpui_mac/Cargo.toml b/crates/gpui_mac/Cargo.toml new file mode 100644 index 0000000000..b4235e02c1 --- /dev/null +++ b/crates/gpui_mac/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "gpui_mac" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +resvg = "0.14" +gpui = {path = "../gpui"} +usvg = { version = "0.14", features = [] } +tiny-skia = "0.5" +uuid = { version = "1.1.2", features = ["v4"] } +time.workspace = true +etagere = "0.2" +ordered-float.workspace = true +postage.workspace = true +smol.workspace = true +ctor.workspace = true +parking_lot.workspace = true +collections = { path = "../collections" } +async-task = "4.0.3" +pathfinder_geometry = "0.5" + +[target.'cfg(target_os = "macos")'.dependencies] +media = { path = "../media" } +anyhow.workspace = true +block = "0.1" +cocoa = "0.24" +core-foundation = { version = "0.9.3", features = ["with-uuid"] } +core-graphics = "0.22.3" +core-text = "19.2" +font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "b2f77d56f450338aa4f7dd2f0197d8c9acb0cf18" } +foreign-types = "0.3" +log.workspace = true +metal = "0.21.0" +objc = "0.2" + +[build-dependencies] +bindgen = "0.65.1" +cc = "1.0.67" diff --git a/crates/gpui/build.rs b/crates/gpui_mac/build.rs similarity index 90% rename from crates/gpui/build.rs rename to crates/gpui_mac/build.rs index 095d5065d9..8b59b605d1 100644 --- a/crates/gpui/build.rs +++ b/crates/gpui_mac/build.rs @@ -12,10 +12,10 @@ fn main() { fn generate_dispatch_bindings() { println!("cargo:rustc-link-lib=framework=System"); - println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h"); + println!("cargo:rerun-if-changed=src/dispatch.h"); let bindings = bindgen::Builder::default() - .header("src/platform/mac/dispatch.h") + .header("src/dispatch.h") .allowlist_var("_dispatch_main_q") .allowlist_function("dispatch_async_f") .parse_callbacks(Box::new(bindgen::CargoCallbacks)) @@ -29,10 +29,10 @@ fn generate_dispatch_bindings() { .expect("couldn't write dispatch bindings"); } -const SHADER_HEADER_PATH: &str = "./src/platform/mac/shaders/shaders.h"; +const SHADER_HEADER_PATH: &str = "./src/shaders/shaders.h"; fn compile_metal_shaders() { - let shader_path = "./src/platform/mac/shaders/shaders.metal"; + let shader_path = "./src/shaders/shaders.metal"; let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air"); let metallib_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.metallib"); diff --git a/crates/gpui/src/platform/mac/appearance.rs b/crates/gpui_mac/src/appearance.rs similarity index 66% rename from crates/gpui/src/platform/mac/appearance.rs rename to crates/gpui_mac/src/appearance.rs index ed1f040699..85d50c6a2d 100644 --- a/crates/gpui/src/platform/mac/appearance.rs +++ b/crates/gpui_mac/src/appearance.rs @@ -1,30 +1,33 @@ use std::ffi::CStr; -use crate::platform::Appearance; use cocoa::{ appkit::{NSAppearanceNameVibrantDark, NSAppearanceNameVibrantLight}, base::id, foundation::NSString, }; +use gpui::platform::Appearance; use objc::{msg_send, sel, sel_impl}; -impl Appearance { - pub unsafe fn from_native(appearance: id) -> Self { +pub trait AppearanceFromNative { + unsafe fn from_native(appearance: id) -> Self; +} +impl AppearanceFromNative for Appearance { + unsafe fn from_native(appearance: id) -> Appearance { let name: id = msg_send![appearance, name]; if name == NSAppearanceNameVibrantLight { - Self::VibrantLight + Appearance::VibrantLight } else if name == NSAppearanceNameVibrantDark { - Self::VibrantDark + Appearance::VibrantDark } else if name == NSAppearanceNameAqua { - Self::Light + Appearance::Light } else if name == NSAppearanceNameDarkAqua { - Self::Dark + Appearance::Dark } else { println!( "unknown appearance: {:?}", CStr::from_ptr(name.UTF8String()) ); - Self::Light + Appearance::Light } } } diff --git a/crates/gpui/src/platform/mac/atlas.rs b/crates/gpui_mac/src/atlas.rs similarity index 99% rename from crates/gpui/src/platform/mac/atlas.rs rename to crates/gpui_mac/src/atlas.rs index a529513ef5..2030dd1208 100644 --- a/crates/gpui/src/platform/mac/atlas.rs +++ b/crates/gpui_mac/src/atlas.rs @@ -1,9 +1,9 @@ -use crate::geometry::{ +use etagere::BucketedAtlasAllocator; +use foreign_types::ForeignType; +use gpui::geometry::{ rect::RectI, vector::{vec2i, Vector2I}, }; -use etagere::BucketedAtlasAllocator; -use foreign_types::ForeignType; use log::warn; use metal::{Device, TextureDescriptor}; use objc::{msg_send, sel, sel_impl}; diff --git a/crates/gpui/src/platform/mac/dispatch.h b/crates/gpui_mac/src/dispatch.h similarity index 100% rename from crates/gpui/src/platform/mac/dispatch.h rename to crates/gpui_mac/src/dispatch.h diff --git a/crates/gpui/src/platform/mac/dispatcher.rs b/crates/gpui_mac/src/dispatcher.rs similarity index 98% rename from crates/gpui/src/platform/mac/dispatcher.rs rename to crates/gpui_mac/src/dispatcher.rs index 6b41676c4c..8ca553afdd 100644 --- a/crates/gpui/src/platform/mac/dispatcher.rs +++ b/crates/gpui_mac/src/dispatcher.rs @@ -10,7 +10,7 @@ use objc::{ }; use std::ffi::c_void; -use crate::platform; +use gpui::platform; include!(concat!(env!("OUT_DIR"), "/dispatch_sys.rs")); diff --git a/crates/gpui/src/platform/mac/event.rs b/crates/gpui_mac/src/event.rs similarity index 98% rename from crates/gpui/src/platform/mac/event.rs rename to crates/gpui_mac/src/event.rs index f25b27f067..3fd67e2bbd 100644 --- a/crates/gpui/src/platform/mac/event.rs +++ b/crates/gpui_mac/src/event.rs @@ -1,12 +1,3 @@ -use crate::{ - geometry::vector::vec2f, - keymap_matcher::Keystroke, - platform::{ - Event, KeyDownEvent, KeyUpEvent, Modifiers, ModifiersChangedEvent, MouseButton, - MouseButtonEvent, MouseExitedEvent, MouseMovedEvent, NavigationDirection, ScrollDelta, - ScrollWheelEvent, TouchPhase, - }, -}; use cocoa::{ appkit::{NSEvent, NSEventModifierFlags, NSEventPhase, NSEventType}, base::{id, YES}, @@ -18,6 +9,15 @@ use core_graphics::{ }; use ctor::ctor; use foreign_types::ForeignType; +use gpui::{ + geometry::vector::vec2f, + keymap_matcher::Keystroke, + platform::{ + Event, KeyDownEvent, KeyUpEvent, Modifiers, ModifiersChangedEvent, MouseButton, + MouseButtonEvent, MouseExitedEvent, MouseMovedEvent, NavigationDirection, ScrollDelta, + ScrollWheelEvent, TouchPhase, + }, +}; use objc::{class, msg_send, sel, sel_impl}; use std::{borrow::Cow, ffi::CStr, mem, os::raw::c_char, ptr}; @@ -86,8 +86,11 @@ unsafe fn read_modifiers(native_event: id) -> Modifiers { } } -impl Event { - pub unsafe fn from_native(native_event: id, window_height: Option) -> Option { +pub trait EventFromNative { + unsafe fn from_native(native_event: id, window_height: Option) -> Option; +} +impl EventFromNative for Event { + unsafe fn from_native(native_event: id, window_height: Option) -> Option { let event_type = native_event.eventType(); // Filter out event types that aren't in the NSEventType enum. diff --git a/crates/gpui/src/platform/mac/fonts.rs b/crates/gpui_mac/src/fonts.rs similarity index 99% rename from crates/gpui/src/platform/mac/fonts.rs rename to crates/gpui_mac/src/fonts.rs index 0414cb8a6c..5ebdf67ac3 100644 --- a/crates/gpui/src/platform/mac/fonts.rs +++ b/crates/gpui_mac/src/fonts.rs @@ -1,15 +1,5 @@ mod open_type; -use crate::{ - fonts::{Features, FontId, GlyphId, Metrics, Properties}, - geometry::{ - rect::{RectF, RectI}, - transform2d::Transform2F, - vector::{vec2f, Vector2F}, - }, - platform::{self, RasterizationOptions}, - text_layout::{Glyph, LineLayout, Run, RunStyle}, -}; use cocoa::appkit::{CGFloat, CGPoint}; use collections::HashMap; use core_foundation::{ @@ -27,6 +17,16 @@ use core_text::{font::CTFont, line::CTLine, string_attributes::kCTFontAttributeN use font_kit::{ handle::Handle, hinting::HintingOptions, source::SystemSource, sources::mem::MemSource, }; +use gpui::{ + fonts::{Features, FontId, GlyphId, Metrics, Properties}, + geometry::{ + rect::{RectF, RectI}, + transform2d::Transform2F, + vector::{vec2f, Vector2F}, + }, + platform::{self, RasterizationOptions}, + text_layout::{Glyph, LineLayout, Run, RunStyle}, +}; use parking_lot::RwLock; use std::{cell::RefCell, char, cmp, convert::TryFrom, ffi::c_void, sync::Arc}; @@ -506,8 +506,8 @@ extern "C" { #[cfg(test)] mod tests { use super::*; - use crate::AppContext; use font_kit::properties::{Style, Weight}; + use gpui::AppContext; use platform::FontSystem as _; #[crate::test(self, retries = 5)] diff --git a/crates/gpui/src/platform/mac/fonts/open_type.rs b/crates/gpui_mac/src/fonts/open_type.rs similarity index 99% rename from crates/gpui/src/platform/mac/fonts/open_type.rs rename to crates/gpui_mac/src/fonts/open_type.rs index 8ee10fdb41..829f2963a0 100644 --- a/crates/gpui/src/platform/mac/fonts/open_type.rs +++ b/crates/gpui_mac/src/fonts/open_type.rs @@ -2,7 +2,6 @@ use std::ptr; -use crate::fonts::Features; use cocoa::appkit::CGFloat; use core_foundation::{base::TCFType, number::CFNumber}; use core_graphics::geometry::CGAffineTransform; @@ -13,6 +12,7 @@ use core_text::{ }, }; use font_kit::font::Font; +use gpui::fonts::Features; const kCaseSensitiveLayoutOffSelector: i32 = 1; const kCaseSensitiveLayoutOnSelector: i32 = 0; diff --git a/crates/gpui/src/platform/mac/geometry.rs b/crates/gpui_mac/src/geometry.rs similarity index 100% rename from crates/gpui/src/platform/mac/geometry.rs rename to crates/gpui_mac/src/geometry.rs diff --git a/crates/gpui/src/platform/mac/image_cache.rs b/crates/gpui_mac/src/image_cache.rs similarity index 99% rename from crates/gpui/src/platform/mac/image_cache.rs rename to crates/gpui_mac/src/image_cache.rs index f5a03ad51e..932dcc2d5a 100644 --- a/crates/gpui/src/platform/mac/image_cache.rs +++ b/crates/gpui_mac/src/image_cache.rs @@ -1,12 +1,12 @@ use super::atlas::{AllocId, AtlasAllocator}; -use crate::{ +use anyhow::anyhow; +use gpui::{ fonts::{FontId, GlyphId}, geometry::{rect::RectI, vector::Vector2I}, platform::{FontSystem, RasterizationOptions}, scene::ImageGlyph, ImageData, }; -use anyhow::anyhow; use metal::{MTLPixelFormat, TextureDescriptor, TextureRef}; use ordered_float::OrderedFloat; use std::{collections::HashMap, mem, sync::Arc}; diff --git a/crates/gpui/src/platform/mac.rs b/crates/gpui_mac/src/lib.rs similarity index 92% rename from crates/gpui/src/platform/mac.rs rename to crates/gpui_mac/src/lib.rs index 342c1c66d0..e88d54741a 100644 --- a/crates/gpui/src/platform/mac.rs +++ b/crates/gpui_mac/src/lib.rs @@ -10,6 +10,8 @@ mod renderer; mod screen; mod sprite_cache; mod status_item; +#[cfg(test)] +mod test; mod window; use cocoa::{ @@ -23,15 +25,15 @@ pub use renderer::Surface; use std::{ops::Range, rc::Rc, sync::Arc}; use window::Window; -use crate::executor; +use gpui::executor; -pub(crate) fn platform() -> Arc { +pub fn platform() -> Arc { Arc::new(MacPlatform::new()) } -pub(crate) fn foreground_platform( +pub fn foreground_platform( foreground: Rc, -) -> Rc { +) -> Rc { Rc::new(MacForegroundPlatform::new(foreground)) } diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui_mac/src/platform.rs similarity index 97% rename from crates/gpui/src/platform/mac/platform.rs rename to crates/gpui_mac/src/platform.rs index ea415cc6a6..506213b08c 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui_mac/src/platform.rs @@ -2,12 +2,7 @@ use super::{ event::key_to_native, screen::Screen, status_item::StatusItem, BoolExt as _, Dispatcher, FontSystem, Window, }; -use crate::{ - executor, - keymap_matcher::KeymapMatcher, - platform::{self, AppVersion, CursorStyle, Event}, - Action, ClipboardItem, Menu, MenuItem, -}; +use crate::event::EventFromNative; use anyhow::{anyhow, Result}; use block::ConcreteBlock; use cocoa::{ @@ -30,6 +25,12 @@ use core_foundation::{ string::{CFString, CFStringRef}, }; use ctor::ctor; +use gpui::{ + executor, + keymap_matcher::KeymapMatcher, + platform::{self, AppVersion, CursorStyle, Event}, + Action, ClipboardItem, Menu, MenuItem, +}; use objc::{ class, declare::ClassDecl, @@ -235,12 +236,12 @@ impl MacForegroundPlatform { .find(|binding| binding.action().eq(action.as_ref())) .map(|binding| binding.keystrokes()); let selector = match os_action { - Some(crate::OsAction::Cut) => selector("cut:"), - Some(crate::OsAction::Copy) => selector("copy:"), - Some(crate::OsAction::Paste) => selector("paste:"), - Some(crate::OsAction::SelectAll) => selector("selectAll:"), - Some(crate::OsAction::Undo) => selector("undo:"), - Some(crate::OsAction::Redo) => selector("redo:"), + Some(gpui::OsAction::Cut) => selector("cut:"), + Some(gpui::OsAction::Copy) => selector("copy:"), + Some(gpui::OsAction::Paste) => selector("paste:"), + Some(gpui::OsAction::SelectAll) => selector("selectAll:"), + Some(gpui::OsAction::Undo) => selector("undo:"), + Some(gpui::OsAction::Redo) => selector("redo:"), None => selector("handleGPUIMenuItem:"), }; @@ -611,14 +612,14 @@ impl platform::Platform for MacPlatform { let text_bytes = NSData::dataWithBytes_length_( nil, - item.text.as_ptr() as *const c_void, - item.text.len() as u64, + item.text().as_ptr() as *const c_void, + item.text().len() as u64, ); self.pasteboard .setData_forType(text_bytes, NSPasteboardTypeString); - if let Some(metadata) = item.metadata.as_ref() { - let hash_bytes = ClipboardItem::text_hash(&item.text).to_be_bytes(); + if let Some(metadata) = item.raw_metadata() { + let hash_bytes = ClipboardItem::text_hash(&item.text()).to_be_bytes(); let hash_bytes = NSData::dataWithBytes_length_( nil, hash_bytes.as_ptr() as *const c_void, @@ -652,21 +653,12 @@ impl platform::Platform for MacPlatform { if let Some((hash, metadata)) = hash_bytes.zip(metadata_bytes) { if hash == ClipboardItem::text_hash(&text) { - Some(ClipboardItem { - text, - metadata: Some(metadata), - }) + Some(ClipboardItem::new(text).with_metadata(metadata)) } else { - Some(ClipboardItem { - text, - metadata: None, - }) + Some(ClipboardItem::new(text)) } } else { - Some(ClipboardItem { - text, - metadata: None, - }) + Some(ClipboardItem::new(text)) } } else { None @@ -868,7 +860,7 @@ impl platform::Platform for MacPlatform { "macOS" } - fn os_version(&self) -> Result { + fn os_version(&self) -> Result { unsafe { let process_info = NSProcessInfo::processInfo(nil); let version = process_info.operatingSystemVersion(); @@ -1097,7 +1089,7 @@ mod security { #[cfg(test)] mod tests { - use crate::platform::Platform; + use gpui::platform::Platform; use super::*; diff --git a/crates/gpui/src/platform/mac/renderer.rs b/crates/gpui_mac/src/renderer.rs similarity index 99% rename from crates/gpui/src/platform/mac/renderer.rs rename to crates/gpui_mac/src/renderer.rs index 24c44bb698..fc53c6815c 100644 --- a/crates/gpui/src/platform/mac/renderer.rs +++ b/crates/gpui_mac/src/renderer.rs @@ -1,5 +1,14 @@ use super::{atlas::AtlasAllocator, image_cache::ImageCache, sprite_cache::SpriteCache}; -use crate::{ +use crate::renderer::shaders::ColorToUchar4; +use cocoa::{ + base::{NO, YES}, + foundation::NSUInteger, + quartzcore::AutoresizingMask, +}; +use core_foundation::base::TCFType; +use foreign_types::ForeignTypeRef; +pub use gpui::scene::Surface; +use gpui::{ color::Color, geometry::{ rect::RectF, @@ -8,13 +17,6 @@ use crate::{ platform, scene::{Glyph, Icon, Image, ImageGlyph, Layer, Quad, Scene, Shadow, Underline}, }; -use cocoa::{ - base::{NO, YES}, - foundation::NSUInteger, - quartzcore::AutoresizingMask, -}; -use core_foundation::base::TCFType; -use foreign_types::ForeignTypeRef; use log::warn; use media::core_video::{self, CVMetalTextureCache}; use metal::{CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange}; @@ -49,11 +51,6 @@ struct PathSprite { shader_data: shaders::GPUISprite, } -pub struct Surface { - pub bounds: RectF, - pub image_buffer: core_video::CVImageBuffer, -} - impl Renderer { pub fn new(is_opaque: bool, fonts: Arc) -> Self { const PIXEL_FORMAT: MTLPixelFormat = MTLPixelFormat::BGRA8Unorm; @@ -1208,7 +1205,7 @@ mod shaders { #![allow(non_camel_case_types)] #![allow(non_snake_case)] - use crate::{ + use gpui::{ color::Color, geometry::vector::{Vector2F, Vector2I}, }; @@ -1247,9 +1244,11 @@ mod shaders { self.to_f32().to_float2() } } - - impl Color { - pub fn to_uchar4(&self) -> vector_uchar4 { + pub trait ColorToUchar4 { + fn to_uchar4(&self) -> vector_uchar4; + } + impl ColorToUchar4 for Color { + fn to_uchar4(&self) -> vector_uchar4 { let mut vec = self.a as vector_uchar4; vec <<= 8; vec |= self.b as vector_uchar4; diff --git a/crates/gpui/src/platform/mac/screen.rs b/crates/gpui_mac/src/screen.rs similarity index 99% rename from crates/gpui/src/platform/mac/screen.rs rename to crates/gpui_mac/src/screen.rs index 3766a13de3..b9a539e03a 100644 --- a/crates/gpui/src/platform/mac/screen.rs +++ b/crates/gpui_mac/src/screen.rs @@ -1,6 +1,5 @@ use std::{any::Any, ffi::c_void}; -use crate::platform; use cocoa::{ appkit::NSScreen, base::{id, nil}, @@ -11,6 +10,7 @@ use core_foundation::{ uuid::{CFUUIDGetUUIDBytes, CFUUIDRef}, }; use core_graphics::display::CGDirectDisplayID; +use gpui::platform; use pathfinder_geometry::rect::RectF; use uuid::Uuid; diff --git a/crates/gpui/src/platform/mac/shaders/shaders.h b/crates/gpui_mac/src/shaders/shaders.h similarity index 100% rename from crates/gpui/src/platform/mac/shaders/shaders.h rename to crates/gpui_mac/src/shaders/shaders.h diff --git a/crates/gpui/src/platform/mac/shaders/shaders.metal b/crates/gpui_mac/src/shaders/shaders.metal similarity index 100% rename from crates/gpui/src/platform/mac/shaders/shaders.metal rename to crates/gpui_mac/src/shaders/shaders.metal diff --git a/crates/gpui/src/platform/mac/sprite_cache.rs b/crates/gpui_mac/src/sprite_cache.rs similarity index 99% rename from crates/gpui/src/platform/mac/sprite_cache.rs rename to crates/gpui_mac/src/sprite_cache.rs index d283fe52aa..7427db71e5 100644 --- a/crates/gpui/src/platform/mac/sprite_cache.rs +++ b/crates/gpui_mac/src/sprite_cache.rs @@ -1,10 +1,10 @@ use super::atlas::AtlasAllocator; -use crate::{ +use collections::hash_map::Entry; +use gpui::{ fonts::{FontId, GlyphId}, geometry::vector::{vec2f, Vector2F, Vector2I}, platform::{self, RasterizationOptions}, }; -use collections::hash_map::Entry; use metal::{MTLPixelFormat, TextureDescriptor}; use ordered_float::OrderedFloat; use std::{borrow::Cow, collections::HashMap, sync::Arc}; diff --git a/crates/gpui/src/platform/mac/status_item.rs b/crates/gpui_mac/src/status_item.rs similarity index 97% rename from crates/gpui/src/platform/mac/status_item.rs rename to crates/gpui_mac/src/status_item.rs index 955b2b659a..6438f2eac9 100644 --- a/crates/gpui/src/platform/mac/status_item.rs +++ b/crates/gpui_mac/src/status_item.rs @@ -1,15 +1,6 @@ -use crate::{ - geometry::{ - rect::RectF, - vector::{vec2f, Vector2F}, - }, - platform::{ - self, - mac::{platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer}, - Event, FontSystem, WindowBounds, - }, - Scene, -}; +use crate::appearance::AppearanceFromNative; +use crate::event::EventFromNative; +use crate::{platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer}; use cocoa::{ appkit::{NSScreen, NSSquareStatusItemLength, NSStatusBar, NSStatusItem, NSView, NSWindow}, base::{id, nil, YES}, @@ -17,6 +8,14 @@ use cocoa::{ }; use ctor::ctor; use foreign_types::ForeignTypeRef; +use gpui::{ + geometry::{ + rect::RectF, + vector::{vec2f, Vector2F}, + }, + platform::{self, Event, FontSystem, WindowBounds}, + Scene, +}; use objc::{ class, declare::ClassDecl, @@ -210,7 +209,7 @@ impl platform::Window for StatusItem { fn prompt( &self, - _: crate::platform::PromptLevel, + _: gpui::platform::PromptLevel, _: &str, _: &[&str], ) -> postage::oneshot::Receiver { diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui_mac/src/test.rs similarity index 92% rename from crates/gpui/src/platform/test.rs rename to crates/gpui_mac/src/test.rs index f949a6cd78..9bb7b58afe 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui_mac/src/test.rs @@ -1,5 +1,7 @@ use super::{AppVersion, CursorStyle, WindowBounds}; -use crate::{ +use anyhow::{anyhow, Result}; +use collections::VecDeque; +use gpui::{ geometry::{ rect::RectF, vector::{vec2f, Vector2F}, @@ -7,8 +9,6 @@ use crate::{ keymap_matcher::KeymapMatcher, Action, ClipboardItem, Menu, }; -use anyhow::{anyhow, Result}; -use collections::VecDeque; use parking_lot::Mutex; use postage::oneshot; use std::{ @@ -64,7 +64,7 @@ impl super::ForegroundPlatform for ForegroundPlatform { fn on_resign_active(&self, _: Box) {} fn on_quit(&self, _: Box) {} fn on_reopen(&self, _: Box) {} - fn on_event(&self, _: Box bool>) {} + fn on_event(&self, _: Box bool>) {} fn on_open_urls(&self, _: Box)>) {} fn run(&self, _on_finish_launching: Box) { @@ -136,11 +136,11 @@ impl super::Platform for Platform { fn quit(&self) {} - fn screen_by_id(&self, _id: uuid::Uuid) -> Option> { + fn screen_by_id(&self, _id: uuid::Uuid) -> Option> { None } - fn screens(&self) -> Vec> { + fn screens(&self) -> Vec> { Default::default() } @@ -165,7 +165,7 @@ impl super::Platform for Platform { self.active_window_id.lock().clone() } - fn add_status_item(&self, id: usize) -> Box { + fn add_status_item(&self, id: usize) -> Box { Box::new(Window::new( id, vec2f(24., 24.), @@ -259,7 +259,7 @@ pub struct Window { id: usize, pub(crate) size: Vector2F, scale_factor: f32, - current_scene: Option, + current_scene: Option, event_handlers: Vec bool>>, pub(crate) resize_handlers: Vec>, pub(crate) moved_handlers: Vec>, @@ -316,11 +316,11 @@ impl super::Window for Window { 24. } - fn appearance(&self) -> crate::platform::Appearance { - crate::platform::Appearance::Light + fn appearance(&self) -> gpui::platform::Appearance { + gpui::platform::Appearance::Light } - fn screen(&self) -> Rc { + fn screen(&self) -> Rc { Rc::new(Screen) } @@ -328,11 +328,11 @@ impl super::Window for Window { self } - fn set_input_handler(&mut self, _: Box) {} + fn set_input_handler(&mut self, _: Box) {} fn prompt( &self, - _: crate::platform::PromptLevel, + _: gpui::platform::PromptLevel, _: &str, _: &[&str], ) -> oneshot::Receiver { @@ -359,13 +359,13 @@ impl super::Window for Window { fn zoom(&self) {} - fn present_scene(&mut self, scene: crate::Scene) { + fn present_scene(&mut self, scene: gpui::Scene) { self.current_scene = Some(scene); } fn toggle_full_screen(&self) {} - fn on_event(&mut self, callback: Box bool>) { + fn on_event(&mut self, callback: Box bool>) { self.event_handlers.push(callback); } diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui_mac/src/window.rs similarity index 99% rename from crates/gpui/src/platform/mac/window.rs rename to crates/gpui_mac/src/window.rs index 3c82538611..10c0405021 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui_mac/src/window.rs @@ -1,18 +1,7 @@ +use crate::appearance::AppearanceFromNative; +use crate::event::EventFromNative; use crate::{ - executor, - geometry::{ - rect::RectF, - vector::{vec2f, Vector2F}, - }, - keymap_matcher::Keystroke, - platform::{ - self, - mac::{ - platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer, screen::Screen, - }, - Event, InputHandler, KeyDownEvent, ModifiersChangedEvent, MouseButton, MouseButtonEvent, - MouseMovedEvent, Scene, WindowBounds, WindowKind, - }, + platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer, screen::Screen, }; use block::ConcreteBlock; use cocoa::{ @@ -27,6 +16,19 @@ use cocoa::{ use core_graphics::display::CGRect; use ctor::ctor; use foreign_types::ForeignTypeRef; +use gpui::{ + executor, + geometry::{ + rect::RectF, + vector::{vec2f, Vector2F}, + }, + keymap_matcher::Keystroke, + platform::{ + self, Event, InputHandler, KeyDownEvent, ModifiersChangedEvent, MouseButton, + MouseButtonEvent, MouseMovedEvent, WindowBounds, WindowKind, + }, + Scene, +}; use objc::{ class, declare::ClassDecl, diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.toml index c1f7e79d58..f66e72e2d7 100644 --- a/crates/language/Cargo.toml +++ b/crates/language/Cargo.toml @@ -36,6 +36,7 @@ sum_tree = { path = "../sum_tree" } text = { path = "../text" } theme = { path = "../theme" } util = { path = "../util" } +util_http = { path = "../util_http" } anyhow.workspace = true async-broadcast = "0.4" diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 5a4d604ce3..9376e352b8 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -46,7 +46,7 @@ use syntax_map::SyntaxSnapshot; use theme::{SyntaxTheme, Theme}; use tree_sitter::{self, Query}; use unicase::UniCase; -use util::http::HttpClient; +use util_http::HttpClient; use util::{merge_json_value_into, post_inc, ResultExt, TryFutureExt as _, UnwrapFuture}; #[cfg(any(test, feature = "test-support"))] diff --git a/crates/node_runtime/Cargo.toml b/crates/node_runtime/Cargo.toml index fce0fdfe50..95c03f402f 100644 --- a/crates/node_runtime/Cargo.toml +++ b/crates/node_runtime/Cargo.toml @@ -10,6 +10,7 @@ doctest = false [dependencies] gpui = { path = "../gpui" } +util_http = { path = "../util_http" } util = { path = "../util" } async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] } async-tar = "0.4.2" diff --git a/crates/node_runtime/src/node_runtime.rs b/crates/node_runtime/src/node_runtime.rs index e2a8d0d003..d85e2d0505 100644 --- a/crates/node_runtime/src/node_runtime.rs +++ b/crates/node_runtime/src/node_runtime.rs @@ -11,7 +11,7 @@ use std::{ path::{Path, PathBuf}, sync::Arc, }; -use util::http::HttpClient; +use util_http::HttpClient; const VERSION: &str = "v18.15.0"; diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index d6578c87ba..a265821987 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -36,6 +36,7 @@ settings = { path = "../settings" } sum_tree = { path = "../sum_tree" } terminal = { path = "../terminal" } util = { path = "../util" } +util_http = { path = "../util_http" } aho-corasick = "0.7" anyhow.workspace = true diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 27d424879f..e5585a47a5 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -75,9 +75,10 @@ use std::{ }; use terminals::Terminals; use util::{ - debug_panic, defer, http::HttpClient, merge_json_value_into, + debug_panic, defer, merge_json_value_into, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _, }; +use util_http::HttpClient; pub use fs::*; pub use worktree::*; @@ -681,7 +682,7 @@ impl Project { ) -> ModelHandle { let mut languages = LanguageRegistry::test(); languages.set_executor(cx.background()); - let http_client = util::http::FakeHttpClient::with_404_response(); + let http_client = util_http::FakeHttpClient::with_404_response(); let client = cx.update(|cx| client::Client::new(http_client.clone(), cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); let project = diff --git a/crates/util/Cargo.toml b/crates/util/Cargo.toml index 8d9594fbeb..1d1ff0dd09 100644 --- a/crates/util/Cargo.toml +++ b/crates/util/Cargo.toml @@ -9,7 +9,7 @@ path = "src/util.rs" doctest = true [features] -test-support = ["tempdir", "git2"] +test-support = [] [dependencies] anyhow.workspace = true @@ -17,15 +17,12 @@ backtrace = "0.3" log.workspace = true lazy_static.workspace = true futures.workspace = true -isahc.workspace = true smol.workspace = true -url = "2.2" + rand.workspace = true rust-embed.workspace = true -tempdir = { workspace = true, optional = true } serde.workspace = true serde_json.workspace = true -git2 = { version = "0.15", default-features = false, optional = true } dirs = "3.0" take-until = "0.2.0" diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs index 71ffacebf3..f3f43f8cca 100644 --- a/crates/util/src/util.rs +++ b/crates/util/src/util.rs @@ -1,7 +1,5 @@ pub mod channel; pub mod fs; -pub mod github; -pub mod http; pub mod paths; #[cfg(any(test, feature = "test-support"))] pub mod test; diff --git a/crates/util_http/Cargo.toml b/crates/util_http/Cargo.toml new file mode 100644 index 0000000000..6c4b5af100 --- /dev/null +++ b/crates/util_http/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "util_http" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +isahc.workspace = true +anyhow.workspace = true +futures.workspace = true +serde_json.workspace = true +smol.workspace = true +serde.workspace = true +log.workspace = true +url = "2.2" + +[features] +test-support = [] + +[dev-dependencies] +tempdir.workspace = true diff --git a/crates/util/src/github.rs b/crates/util_http/src/github.rs similarity index 98% rename from crates/util/src/github.rs rename to crates/util_http/src/github.rs index b1e981ae49..f8a3ae7dd2 100644 --- a/crates/util/src/github.rs +++ b/crates/util_http/src/github.rs @@ -1,4 +1,4 @@ -use crate::http::HttpClient; +use crate::HttpClient; use anyhow::{anyhow, Context, Result}; use futures::AsyncReadExt; use serde::Deserialize; diff --git a/crates/util/src/http.rs b/crates/util_http/src/lib.rs similarity index 99% rename from crates/util/src/http.rs rename to crates/util_http/src/lib.rs index e29768a53e..9480bf6e99 100644 --- a/crates/util/src/http.rs +++ b/crates/util_http/src/lib.rs @@ -1,3 +1,5 @@ +pub mod github; + pub use anyhow::{anyhow, Result}; use futures::future::BoxFuture; use isahc::config::{Configurable, RedirectPolicy}; diff --git a/crates/workspace/src/shared_screen.rs b/crates/workspace/src/shared_screen.rs index 977e167f60..8ba806bd46 100644 --- a/crates/workspace/src/shared_screen.rs +++ b/crates/workspace/src/shared_screen.rs @@ -80,7 +80,7 @@ impl View for SharedScreen { vec2f(frame.width() as f32, frame.height() as f32), ); let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.; - scene.push_surface(gpui::platform::mac::Surface { + scene.push_surface(gpui::scene::Surface { bounds: RectF::new(origin, size), image_buffer: frame.image(), }); diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 3bf500057f..3edb4d0769 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -20,7 +20,7 @@ activity_indicator = { path = "../activity_indicator" } auto_update = { path = "../auto_update" } breadcrumbs = { path = "../breadcrumbs" } call = { path = "../call" } -cli = { path = "../cli" } +cli_rpc = { path = "../cli_rpc" } collab_ui = { path = "../collab_ui" } collections = { path = "../collections" } command_palette = { path = "../command_palette" } @@ -63,9 +63,11 @@ terminal_view = { path = "../terminal_view" } theme = { path = "../theme" } theme_selector = { path = "../theme_selector" } util = { path = "../util" } +util_http = { path = "../util_http" } vim = { path = "../vim" } workspace = { path = "../workspace" } welcome = { path = "../welcome" } +gpui_mac = {path = "../gpui_mac"} anyhow.workspace = true async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] } diff --git a/crates/zed/src/languages/c.rs b/crates/zed/src/languages/c.rs index 241b11b47c..1618b6bbf0 100644 --- a/crates/zed/src/languages/c.rs +++ b/crates/zed/src/languages/c.rs @@ -6,10 +6,10 @@ use smol::fs::{self, File}; use std::{any::Any, path::PathBuf, sync::Arc}; use util::{ fs::remove_matching, - github::{latest_github_release, GitHubLspBinaryVersion}, + ResultExt, }; - +use util_http::github::{latest_github_release, GitHubLspBinaryVersion}; pub struct CLspAdapter; #[async_trait] diff --git a/crates/zed/src/languages/elixir.rs b/crates/zed/src/languages/elixir.rs index 22aaedc069..db4c680baa 100644 --- a/crates/zed/src/languages/elixir.rs +++ b/crates/zed/src/languages/elixir.rs @@ -15,10 +15,11 @@ use std::{ }; use util::{ fs::remove_matching, - github::{latest_github_release, GitHubLspBinaryVersion}, + ResultExt, }; +use util_http::github::{latest_github_release, GitHubLspBinaryVersion}; pub struct ElixirLspAdapter; #[async_trait] diff --git a/crates/zed/src/languages/go.rs b/crates/zed/src/languages/go.rs index 34364d0b7f..0fa2b8152c 100644 --- a/crates/zed/src/languages/go.rs +++ b/crates/zed/src/languages/go.rs @@ -17,8 +17,8 @@ use std::{ Arc, }, }; -use util::{fs::remove_matching, github::latest_github_release, ResultExt}; - +use util::{fs::remove_matching, ResultExt}; +use util_http::github::latest_github_release; fn server_binary_arguments() -> Vec { vec!["-mode=stdio".into()] } diff --git a/crates/zed/src/languages/lua.rs b/crates/zed/src/languages/lua.rs index 7f63a1fae2..7cd4b1accb 100644 --- a/crates/zed/src/languages/lua.rs +++ b/crates/zed/src/languages/lua.rs @@ -8,10 +8,10 @@ use smol::fs; use std::{any::Any, env::consts, ffi::OsString, path::PathBuf}; use util::{ async_iife, - github::{latest_github_release, GitHubLspBinaryVersion}, + ResultExt, }; - +use util_http::github::{latest_github_release, GitHubLspBinaryVersion}; #[derive(Copy, Clone)] pub struct LuaLspAdapter; diff --git a/crates/zed/src/languages/rust.rs b/crates/zed/src/languages/rust.rs index e60846b70a..5822835635 100644 --- a/crates/zed/src/languages/rust.rs +++ b/crates/zed/src/languages/rust.rs @@ -9,9 +9,10 @@ use smol::fs::{self, File}; use std::{any::Any, borrow::Cow, env::consts, path::PathBuf, str, sync::Arc}; use util::{ fs::remove_matching, - github::{latest_github_release, GitHubLspBinaryVersion}, + ResultExt, }; +use util_http::github::{latest_github_release, GitHubLspBinaryVersion}; pub struct RustLspAdapter; diff --git a/crates/zed/src/languages/typescript.rs b/crates/zed/src/languages/typescript.rs index 662e73ea33..e1a0f40a5e 100644 --- a/crates/zed/src/languages/typescript.rs +++ b/crates/zed/src/languages/typescript.rs @@ -16,9 +16,8 @@ use std::{ path::{Path, PathBuf}, sync::Arc, }; -use util::{fs::remove_matching, github::latest_github_release}; -use util::{github::GitHubLspBinaryVersion, ResultExt}; - +use util::{fs::remove_matching, ResultExt}; +use util_http::github::{latest_github_release, GitHubLspBinaryVersion}; fn typescript_server_binary_arguments(server_path: &Path) -> Vec { vec![ server_path.into(), diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 23ecbf978b..e96909c8fc 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result}; use backtrace::Backtrace; -use cli::{ +use cli_rpc::{ ipc::{self, IpcSender}, CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME, }; @@ -45,12 +45,14 @@ use std::{ use sum_tree::Bias; use terminal_view::{get_working_directory, TerminalSettings, TerminalView}; use util::{ - http::{self, HttpClient}, + paths::PathLikeWithPosition, }; +use util_http::{self as http, HttpClient}; use welcome::{show_welcome_experience, FIRST_OPEN}; use fs::RealFs; +use gpui_mac::{foreground_platform, platform}; #[cfg(debug_assertions)] use staff_mode::StaffMode; use util::{channel::RELEASE_CHANNEL, paths, ResultExt, TryFutureExt}; @@ -59,14 +61,17 @@ use zed::{ assets::Assets, build_window_options, handle_keymap_file_changes, initialize_workspace, languages, menus, }; - fn main() { let http = http::client(); init_paths(); init_logger(); log::info!("========== starting zed =========="); - let mut app = gpui::App::new(Assets).unwrap(); + let platform = platform(); + let foreground = + std::rc::Rc::new(gpui::executor::Foreground::platform(platform.dispatcher()).unwrap()); + let fplatform = foreground_platform(foreground); + let mut app = gpui::App::new(Assets, platform, fplatform).unwrap(); init_panic_hook(&app); @@ -663,7 +668,7 @@ async fn watch_languages(_: Arc, _: Arc) -> Option<()> fn connect_to_cli( server_name: &str, ) -> Result<(mpsc::Receiver, IpcSender)> { - let handshake_tx = cli::ipc::IpcSender::::connect(server_name.to_string()) + let handshake_tx = cli_rpc::ipc::IpcSender::::connect(server_name.to_string()) .context("error connecting to cli")?; let (request_tx, request_rx) = ipc::channel::()?; let (response_tx, response_rx) = ipc::channel::()?;