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"))]
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 {
@ -100,17 +109,20 @@ impl BackgroundExecutor {
background_only: bool,
future: impl Future<Output = R>,
) -> R {
dbg!("block_internal");
pin_mut!(future);
let (parker, unparker) = parking::pair();
let awoken = Arc::new(AtomicBool::new(false));
let awoken2 = awoken.clone();
let waker = waker_fn(move || {
dbg!("WAKING UP.");
awoken2.store(true, SeqCst);
unparker.unpark();
});
let mut cx = std::task::Context::from_waker(&waker);
dbg!("BOOOP");
loop {
match future.as_mut().poll(&mut cx) {
Poll::Ready(result) => return result,
@ -131,7 +143,9 @@ impl BackgroundExecutor {
panic!("parked with nothing left to run\n{:?}", backtrace_message)
}
}
dbg!("PARKING!");
parker.park();
dbg!("CONTINUING!");
}
}
}

View file

@ -877,14 +877,17 @@ impl Project {
)
});
for path in root_paths {
dbg!(&path);
let (tree, _) = project
.update(cx, |project, cx| {
project.find_or_create_local_worktree(path, true, cx)
})
.await
.unwrap();
dbg!("aaa");
tree.update(cx, |tree, _| tree.as_local().unwrap().scan_complete())
.await;
dbg!("bbb");
}
project
}
@ -5990,8 +5993,10 @@ impl Project {
) -> Task<Result<(Model<Worktree>, PathBuf)>> {
let abs_path = abs_path.as_ref();
if let Some((tree, relative_path)) = self.find_local_worktree(abs_path, cx) {
dbg!("shortcut");
Task::ready(Ok((tree, relative_path)))
} else {
dbg!("long cut");
let worktree = self.create_local_worktree(abs_path, visible, cx);
cx.background_executor()
.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
// snapshot's "root name", which will be used for the purpose of fuzzy matching.
let abs_path = path.into();
eprintln!("get root metadata");
let metadata = fs
.metadata(&abs_path)
.await
.context("failed to stat worktree path")?;
eprintln!("got root metadata");
cx.build_model(move |cx: &mut ModelContext<Worktree>| {
let root_name = abs_path
.file_name()

View file

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