Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
Piotr Osiewicz
37a74e8412 Add new util_http crate 2023-06-23 17:21:02 +02:00
Piotr Osiewicz
f34014b279 Extract cli's communication with Zed to a separate crate 2023-06-23 16:07:28 +02:00
Piotr Osiewicz
990dac51aa Extract gpui_mac out of gpui 2023-06-23 15:52:31 +02:00
62 changed files with 356 additions and 235 deletions

91
Cargo.lock generated
View file

@ -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",

View file

@ -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" }

View file

@ -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

View file

@ -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";

View file

@ -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"

View file

@ -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,

11
crates/cli_rpc/Cargo.toml Normal file
View file

@ -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

View file

@ -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" }

View file

@ -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) {

View file

@ -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;

View file

@ -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<Peer>,

View file

@ -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)]

View file

@ -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

View file

@ -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]);

View file

@ -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"

View file

@ -138,10 +138,12 @@ pub trait BorrowWindowContext {
pub struct App(Rc<RefCell<AppContext>>);
impl App {
pub fn new(asset_source: impl AssetSource) -> Result<Self> {
let platform = platform::current::platform();
pub fn new(
asset_source: impl AssetSource,
platform: Arc<dyn Platform>,
foreground_platform: Rc<dyn platform::ForegroundPlatform>,
) -> Result<Self> {
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()),

View file

@ -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()

View file

@ -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;

View file

@ -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<dyn FnMut()>);
fn on_resign_active(&self, callback: Box<dyn FnMut()>);
fn on_quit(&self, callback: Box<dyn FnMut()>);
@ -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 {

View file

@ -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,

View file

@ -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"

View file

@ -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");

View file

@ -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
}
}
}

View file

@ -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};

View file

@ -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"));

View file

@ -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<f32>) -> Option<Self> {
pub trait EventFromNative {
unsafe fn from_native(native_event: id, window_height: Option<f32>) -> Option<Event>;
}
impl EventFromNative for Event {
unsafe fn from_native(native_event: id, window_height: Option<f32>) -> Option<Event> {
let event_type = native_event.eventType();
// Filter out event types that aren't in the NSEventType enum.

View file

@ -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)]

View file

@ -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;

View file

@ -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};

View file

@ -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<dyn super::Platform> {
pub fn platform() -> Arc<dyn gpui::platform::Platform> {
Arc::new(MacPlatform::new())
}
pub(crate) fn foreground_platform(
pub fn foreground_platform(
foreground: Rc<executor::Foreground>,
) -> Rc<dyn super::ForegroundPlatform> {
) -> Rc<dyn gpui::platform::ForegroundPlatform> {
Rc::new(MacForegroundPlatform::new(foreground))
}

View file

@ -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<crate::platform::AppVersion> {
fn os_version(&self) -> Result<gpui::platform::AppVersion> {
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::*;

View file

@ -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<dyn platform::FontSystem>) -> 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;

View file

@ -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;

View file

@ -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};

View file

@ -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<usize> {

View file

@ -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<dyn FnMut()>) {}
fn on_quit(&self, _: Box<dyn FnMut()>) {}
fn on_reopen(&self, _: Box<dyn FnMut()>) {}
fn on_event(&self, _: Box<dyn FnMut(crate::platform::Event) -> bool>) {}
fn on_event(&self, _: Box<dyn FnMut(gpui::platform::Event) -> bool>) {}
fn on_open_urls(&self, _: Box<dyn FnMut(Vec<String>)>) {}
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
@ -136,11 +136,11 @@ impl super::Platform for Platform {
fn quit(&self) {}
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn crate::platform::Screen>> {
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn gpui::platform::Screen>> {
None
}
fn screens(&self) -> Vec<Rc<dyn crate::platform::Screen>> {
fn screens(&self) -> Vec<Rc<dyn gpui::platform::Screen>> {
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<dyn crate::platform::Window> {
fn add_status_item(&self, id: usize) -> Box<dyn gpui::platform::Window> {
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<crate::Scene>,
current_scene: Option<gpui::Scene>,
event_handlers: Vec<Box<dyn FnMut(super::Event) -> bool>>,
pub(crate) resize_handlers: Vec<Box<dyn FnMut()>>,
pub(crate) moved_handlers: Vec<Box<dyn FnMut()>>,
@ -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<dyn crate::platform::Screen> {
fn screen(&self) -> Rc<dyn gpui::platform::Screen> {
Rc::new(Screen)
}
@ -328,11 +328,11 @@ impl super::Window for Window {
self
}
fn set_input_handler(&mut self, _: Box<dyn crate::platform::InputHandler>) {}
fn set_input_handler(&mut self, _: Box<dyn gpui::platform::InputHandler>) {}
fn prompt(
&self,
_: crate::platform::PromptLevel,
_: gpui::platform::PromptLevel,
_: &str,
_: &[&str],
) -> oneshot::Receiver<usize> {
@ -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<dyn FnMut(crate::platform::Event) -> bool>) {
fn on_event(&mut self, callback: Box<dyn FnMut(gpui::platform::Event) -> bool>) {
self.event_handlers.push(callback);
}

View file

@ -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,

View file

@ -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"

View file

@ -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"))]

View file

@ -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"

View file

@ -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";

View file

@ -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

View file

@ -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<Project> {
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 =

View file

@ -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"

View file

@ -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;

View file

@ -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

View file

@ -1,4 +1,4 @@
use crate::http::HttpClient;
use crate::HttpClient;
use anyhow::{anyhow, Context, Result};
use futures::AsyncReadExt;
use serde::Deserialize;

View file

@ -1,3 +1,5 @@
pub mod github;
pub use anyhow::{anyhow, Result};
use futures::future::BoxFuture;
use isahc::config::{Configurable, RedirectPolicy};

View file

@ -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(),
});

View file

@ -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"] }

View file

@ -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]

View file

@ -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]

View file

@ -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<OsString> {
vec!["-mode=stdio".into()]
}

View file

@ -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;

View file

@ -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;

View file

@ -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<OsString> {
vec![
server_path.into(),

View file

@ -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<dyn Fs>, _: Arc<LanguageRegistry>) -> Option<()>
fn connect_to_cli(
server_name: &str,
) -> Result<(mpsc::Receiver<CliRequest>, IpcSender<CliResponse>)> {
let handshake_tx = cli::ipc::IpcSender::<IpcHandshake>::connect(server_name.to_string())
let handshake_tx = cli_rpc::ipc::IpcSender::<IpcHandshake>::connect(server_name.to_string())
.context("error connecting to cli")?;
let (request_tx, request_rx) = ipc::channel::<CliRequest>()?;
let (response_tx, response_rx) = ipc::channel::<CliResponse>()?;