wip

KCaverly created

Change summary

crates/gpui2/src/app.rs       |   6 
crates/gpui2/src/platform.rs  |  10 
crates/gpui2/src/window.rs    |   2 
crates/workspace2/src/item.rs |   4 
crates/zed2/src/zed2.rs       | 197 ++++++++++++++++++------------------
5 files changed, 109 insertions(+), 110 deletions(-)

Detailed changes

crates/gpui2/src/app.rs 🔗

@@ -120,7 +120,7 @@ type FrameCallback = Box<dyn FnOnce(&mut WindowContext) + Send>;
 type Handler = Box<dyn FnMut(&mut AppContext) -> bool + Send + 'static>;
 type Listener = Box<dyn FnMut(&dyn Any, &mut AppContext) -> bool + Send + 'static>;
 type QuitHandler = Box<dyn FnMut(&mut AppContext) -> BoxFuture<'static, ()> + Send + 'static>;
-type ReleaseListener = Box<dyn FnMut(&mut dyn Any, &mut AppContext) + Send + 'static>;
+type ReleaseListener = Box<dyn FnOnce(&mut dyn Any, &mut AppContext) + Send + 'static>;
 
 pub struct AppContext {
     this: Weak<Mutex<AppContext>>,
@@ -408,7 +408,7 @@ impl AppContext {
             for (entity_id, mut entity) in dropped {
                 self.observers.remove(&entity_id);
                 self.event_listeners.remove(&entity_id);
-                for mut release_callback in self.release_listeners.remove(&entity_id) {
+                for release_callback in self.release_listeners.remove(&entity_id) {
                     release_callback(&mut entity, self);
                 }
             }
@@ -697,7 +697,7 @@ impl AppContext {
     pub fn observe_release<E, T>(
         &mut self,
         handle: &E,
-        mut on_release: impl FnMut(&mut T, &mut AppContext) + Send + 'static,
+        on_release: impl FnOnce(&mut T, &mut AppContext) + Send + 'static,
     ) -> Subscription
     where
         E: Entity<T>,

crates/gpui2/src/platform.rs 🔗

@@ -393,18 +393,18 @@ impl Bind for WindowBounds {
             }
         };
 
-        todo!()
         // statement.bind(
         //     &region.map(|region| {
         //         (
-        //             region.min_x(),
-        //             region.min_y(),
-        //             region.width(),
-        //             region.height(),
+        //             region.origin.x,
+        //             region.origin.y,
+        //             region.size.width,
+        //             region.size.height,
         //         )
         //     }),
         //     next_index,
         // )
+        todo!()
     }
 }
 

crates/gpui2/src/window.rs 🔗

@@ -1675,7 +1675,7 @@ impl<'a, 'w, V: 'static> ViewContext<'a, 'w, V> {
 
     pub fn on_release(
         &mut self,
-        mut on_release: impl FnMut(&mut V, &mut WindowContext) + Send + 'static,
+        on_release: impl FnOnce(&mut V, &mut WindowContext) + Send + 'static,
     ) -> Subscription {
         let window_handle = self.window.handle;
         self.app.release_listeners.insert(

crates/workspace2/src/item.rs 🔗

@@ -255,7 +255,7 @@ pub trait ItemHandle: 'static + Send {
     fn on_release(
         &mut self,
         cx: &mut AppContext,
-        callback: Box<dyn FnMut(&mut AppContext) + Send>,
+        callback: Box<dyn FnOnce(&mut AppContext) + Send>,
     ) -> gpui2::Subscription;
     fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
     fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
@@ -573,7 +573,7 @@ impl<T: Item> ItemHandle for View<T> {
     fn on_release(
         &mut self,
         cx: &mut AppContext,
-        mut callback: Box<dyn FnMut(&mut AppContext) + Send>,
+        callback: Box<dyn FnOnce(&mut AppContext) + Send>,
     ) -> gpui2::Subscription {
         cx.observe_release(self, move |_, cx| callback(cx))
     }

crates/zed2/src/zed2.rs 🔗

@@ -4,9 +4,8 @@ mod only_instance;
 mod open_listener;
 
 pub use assets::*;
-use client2::{Client, UserStore};
 use collections::HashMap;
-use gpui2::{AsyncAppContext, Model};
+use gpui2::{AsyncAppContext, Point};
 pub use only_instance::*;
 pub use open_listener::*;
 
@@ -21,6 +20,7 @@ use futures::{
 };
 use std::{path::Path, sync::Arc, thread, time::Duration};
 use util::{paths::PathLikeWithPosition, ResultExt};
+use workspace2::AppState;
 
 pub fn connect_to_cli(
     server_name: &str,
@@ -51,11 +51,6 @@ pub fn connect_to_cli(
     Ok((async_request_rx, response_tx))
 }
 
-pub struct AppState {
-    pub client: Arc<Client>,
-    pub user_store: Model<UserStore>,
-}
-
 pub async fn handle_cli_connection(
     (mut requests, responses): (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),
     app_state: Arc<AppState>,
@@ -96,118 +91,122 @@ pub async fn handle_cli_connection(
                             }
                             Some(path)
                         })
-                        .collect()
+                        .collect::<Vec<_>>()
                 };
 
                 let mut errored = false;
 
-                match cx
+                if let Some(open_paths_task) = cx
                     .update(|cx| workspace2::open_paths(&paths, &app_state, None, cx))
-                    .await
+                    .log_err()
                 {
-                    Ok((workspace, items)) => {
-                        let mut item_release_futures = Vec::new();
+                    match open_paths_task.await {
+                        Ok((workspace, items)) => {
+                            let mut item_release_futures = Vec::new();
+
+                            for (item, path) in items.into_iter().zip(&paths) {
+                                match item {
+                                    Some(Ok(mut item)) => {
+                                        if let Some(point) = caret_positions.remove(path) {
+                                            todo!()
+                                            // if let Some(active_editor) = item.downcast::<Editor>() {
+                                            //     active_editor
+                                            //         .downgrade()
+                                            //         .update(&mut cx, |editor, cx| {
+                                            //             let snapshot =
+                                            //                 editor.snapshot(cx).display_snapshot;
+                                            //             let point = snapshot
+                                            //                 .buffer_snapshot
+                                            //                 .clip_point(point, Bias::Left);
+                                            //             editor.change_selections(
+                                            //                 Some(Autoscroll::center()),
+                                            //                 cx,
+                                            //                 |s| s.select_ranges([point..point]),
+                                            //             );
+                                            //         })
+                                            //         .log_err();
+                                            // }
+                                        }
 
-                        for (item, path) in items.into_iter().zip(&paths) {
-                            match item {
-                                Some(Ok(item)) => {
-                                    if let Some(point) = caret_positions.remove(path) {
-                                        todo!()
-                                        // if let Some(active_editor) = item.downcast::<Editor>() {
-                                        //     active_editor
-                                        //         .downgrade()
-                                        //         .update(&mut cx, |editor, cx| {
-                                        //             let snapshot =
-                                        //                 editor.snapshot(cx).display_snapshot;
-                                        //             let point = snapshot
-                                        //                 .buffer_snapshot
-                                        //                 .clip_point(point, Bias::Left);
-                                        //             editor.change_selections(
-                                        //                 Some(Autoscroll::center()),
-                                        //                 cx,
-                                        //                 |s| s.select_ranges([point..point]),
-                                        //             );
-                                        //         })
-                                        //         .log_err();
-                                        // }
+                                        let released = oneshot::channel();
+                                        cx.update(move |cx| {
+                                            item.on_release(
+                                                cx,
+                                                Box::new(move |_| {
+                                                    let _ = released.0.send(());
+                                                }),
+                                            )
+                                            .detach();
+                                        });
+                                        item_release_futures.push(released.1);
                                     }
-
-                                    let released = oneshot::channel();
-                                    cx.update(|cx| {
-                                        item.on_release(
-                                            cx,
-                                            Box::new(move |_| {
-                                                let _ = released.0.send(());
-                                            }),
-                                        )
-                                        .detach();
-                                    });
-                                    item_release_futures.push(released.1);
-                                }
-                                Some(Err(err)) => {
-                                    responses
-                                        .send(CliResponse::Stderr {
-                                            message: format!("error opening {:?}: {}", path, err),
-                                        })
-                                        .log_err();
-                                    errored = true;
+                                    Some(Err(err)) => {
+                                        responses
+                                            .send(CliResponse::Stderr {
+                                                message: format!(
+                                                    "error opening {:?}: {}",
+                                                    path, err
+                                                ),
+                                            })
+                                            .log_err();
+                                        errored = true;
+                                    }
+                                    None => {}
                                 }
-                                None => {}
                             }
-                        }
 
-                        if wait {
-                            let executor = cx.executor();
-                            let wait = async move {
-                                if paths.is_empty() {
-                                    let (done_tx, done_rx) = oneshot::channel();
-                                    if let Some(workspace) = workspace.upgrade(&cx) {
-                                        let _subscription = cx.update(|cx| {
-                                            cx.observe_release(&workspace, move |_, _| {
-                                                let _ = done_tx.send(());
-                                            })
-                                        });
+                            if wait {
+                                let executor = cx.executor().clone();
+                                let wait = async move {
+                                    if paths.is_empty() {
+                                        let (done_tx, done_rx) = oneshot::channel();
+                                        let _subscription =
+                                            cx.update_window_root(&workspace, move |_, cx| {
+                                                cx.on_release(|_, _| {
+                                                    let _ = done_tx.send(());
+                                                })
+                                            });
                                         drop(workspace);
                                         let _ = done_rx.await;
-                                    }
-                                } else {
-                                    let _ =
-                                        futures::future::try_join_all(item_release_futures).await;
-                                };
-                            }
-                            .fuse();
-                            futures::pin_mut!(wait);
-
-                            loop {
-                                // Repeatedly check if CLI is still open to avoid wasting resources
-                                // waiting for files or workspaces to close.
-                                let mut timer = executor.timer(Duration::from_secs(1)).fuse();
-                                futures::select_biased! {
-                                    _ = wait => break,
-                                    _ = timer => {
-                                        if responses.send(CliResponse::Ping).is_err() {
-                                            break;
+                                    } else {
+                                        let _ = futures::future::try_join_all(item_release_futures)
+                                            .await;
+                                    };
+                                }
+                                .fuse();
+                                futures::pin_mut!(wait);
+
+                                loop {
+                                    // Repeatedly check if CLI is still open to avoid wasting resources
+                                    // waiting for files or workspaces to close.
+                                    let mut timer = executor.timer(Duration::from_secs(1)).fuse();
+                                    futures::select_biased! {
+                                        _ = wait => break,
+                                        _ = timer => {
+                                            if responses.send(CliResponse::Ping).is_err() {
+                                                break;
+                                            }
                                         }
                                     }
                                 }
                             }
                         }
+                        Err(error) => {
+                            errored = true;
+                            responses
+                                .send(CliResponse::Stderr {
+                                    message: format!("error opening {:?}: {}", paths, error),
+                                })
+                                .log_err();
+                        }
                     }
-                    Err(error) => {
-                        errored = true;
-                        responses
-                            .send(CliResponse::Stderr {
-                                message: format!("error opening {:?}: {}", paths, error),
-                            })
-                            .log_err();
-                    }
-                }
 
-                responses
-                    .send(CliResponse::Exit {
-                        status: i32::from(errored),
-                    })
-                    .log_err();
+                    responses
+                        .send(CliResponse::Exit {
+                            status: i32::from(errored),
+                        })
+                        .log_err();
+                }
             }
         }
     }