beautiful diff

This commit is contained in:
Conrad Irwin 2023-11-01 15:31:37 -06:00
parent cd10ba9e06
commit 90facc051a
5 changed files with 507 additions and 474 deletions

View file

@ -88,7 +88,16 @@ impl BackgroundExecutor {
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub fn block_test<R>(&self, future: impl Future<Output = R>) -> R { pub fn block_test<R>(&self, future: impl Future<Output = R>) -> R {
self.block_internal(false, future) let (runnable, task) = unsafe {
async_task::spawn_unchecked(future, {
let dispatcher = self.dispatcher.clone();
move |runnable| dispatcher.dispatch_on_main_thread(runnable)
})
};
runnable.schedule();
self.block_internal(false, task)
} }
pub fn block<R>(&self, future: impl Future<Output = R>) -> R { pub fn block<R>(&self, future: impl Future<Output = R>) -> R {
@ -100,17 +109,20 @@ impl BackgroundExecutor {
background_only: bool, background_only: bool,
future: impl Future<Output = R>, future: impl Future<Output = R>,
) -> R { ) -> R {
dbg!("block_internal");
pin_mut!(future); pin_mut!(future);
let (parker, unparker) = parking::pair(); let (parker, unparker) = parking::pair();
let awoken = Arc::new(AtomicBool::new(false)); let awoken = Arc::new(AtomicBool::new(false));
let awoken2 = awoken.clone(); let awoken2 = awoken.clone();
let waker = waker_fn(move || { let waker = waker_fn(move || {
dbg!("WAKING UP.");
awoken2.store(true, SeqCst); awoken2.store(true, SeqCst);
unparker.unpark(); unparker.unpark();
}); });
let mut cx = std::task::Context::from_waker(&waker); let mut cx = std::task::Context::from_waker(&waker);
dbg!("BOOOP");
loop { loop {
match future.as_mut().poll(&mut cx) { match future.as_mut().poll(&mut cx) {
Poll::Ready(result) => return result, Poll::Ready(result) => return result,
@ -131,7 +143,9 @@ impl BackgroundExecutor {
panic!("parked with nothing left to run\n{:?}", backtrace_message) panic!("parked with nothing left to run\n{:?}", backtrace_message)
} }
} }
dbg!("PARKING!");
parker.park(); parker.park();
dbg!("CONTINUING!");
} }
} }
} }

View file

@ -877,14 +877,17 @@ impl Project {
) )
}); });
for path in root_paths { for path in root_paths {
dbg!(&path);
let (tree, _) = project let (tree, _) = project
.update(cx, |project, cx| { .update(cx, |project, cx| {
project.find_or_create_local_worktree(path, true, cx) project.find_or_create_local_worktree(path, true, cx)
}) })
.await .await
.unwrap(); .unwrap();
dbg!("aaa");
tree.update(cx, |tree, _| tree.as_local().unwrap().scan_complete()) tree.update(cx, |tree, _| tree.as_local().unwrap().scan_complete())
.await; .await;
dbg!("bbb");
} }
project project
} }
@ -5990,8 +5993,10 @@ impl Project {
) -> Task<Result<(Model<Worktree>, PathBuf)>> { ) -> Task<Result<(Model<Worktree>, PathBuf)>> {
let abs_path = abs_path.as_ref(); let abs_path = abs_path.as_ref();
if let Some((tree, relative_path)) = self.find_local_worktree(abs_path, cx) { if let Some((tree, relative_path)) = self.find_local_worktree(abs_path, cx) {
dbg!("shortcut");
Task::ready(Ok((tree, relative_path))) Task::ready(Ok((tree, relative_path)))
} else { } else {
dbg!("long cut");
let worktree = self.create_local_worktree(abs_path, visible, cx); let worktree = self.create_local_worktree(abs_path, visible, cx);
cx.background_executor() cx.background_executor()
.spawn(async move { Ok((worktree.await?, PathBuf::new())) }) .spawn(async move { Ok((worktree.await?, PathBuf::new())) })

File diff suppressed because it is too large Load diff

View file

@ -297,11 +297,15 @@ impl Worktree {
// After determining whether the root entry is a file or a directory, populate the // After determining whether the root entry is a file or a directory, populate the
// snapshot's "root name", which will be used for the purpose of fuzzy matching. // snapshot's "root name", which will be used for the purpose of fuzzy matching.
let abs_path = path.into(); let abs_path = path.into();
eprintln!("get root metadata");
let metadata = fs let metadata = fs
.metadata(&abs_path) .metadata(&abs_path)
.await .await
.context("failed to stat worktree path")?; .context("failed to stat worktree path")?;
eprintln!("got root metadata");
cx.build_model(move |cx: &mut ModelContext<Worktree>| { cx.build_model(move |cx: &mut ModelContext<Worktree>| {
let root_name = abs_path let root_name = abs_path
.file_name() .file_name()

View file

@ -559,7 +559,6 @@ mod tests {
use async_tungstenite::tungstenite::Message as WebSocketMessage; use async_tungstenite::tungstenite::Message as WebSocketMessage;
use gpui2::TestAppContext; use gpui2::TestAppContext;
#[ctor::ctor]
fn init_logger() { fn init_logger() {
if std::env::var("RUST_LOG").is_ok() { if std::env::var("RUST_LOG").is_ok() {
env_logger::init(); env_logger::init();
@ -568,6 +567,8 @@ mod tests {
#[gpui2::test(iterations = 50)] #[gpui2::test(iterations = 50)]
async fn test_request_response(cx: &mut TestAppContext) { async fn test_request_response(cx: &mut TestAppContext) {
init_logger();
let executor = cx.executor(); let executor = cx.executor();
// create 2 clients connected to 1 server // create 2 clients connected to 1 server