Get integration tests passing

* Fix misuse of guest buffer's id as its remote id

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-01-21 17:44:24 -08:00
parent f1fc0bde99
commit 2712cadaf6
3 changed files with 35 additions and 53 deletions

View file

@ -427,7 +427,7 @@ impl Project {
for worktree in this.worktrees(cx).collect::<Vec<_>>() { for worktree in this.worktrees(cx).collect::<Vec<_>>() {
worktree.update(cx, |worktree, cx| { worktree.update(cx, |worktree, cx| {
let worktree = worktree.as_local_mut().unwrap(); let worktree = worktree.as_local_mut().unwrap();
tasks.push(worktree.share(cx)); tasks.push(worktree.share(project_id, cx));
}); });
} }
}); });
@ -526,12 +526,14 @@ impl Project {
cx.spawn(move |this, mut cx| async move { cx.spawn(move |this, mut cx| async move {
let load_result = load_buffer.await; let load_result = load_buffer.await;
*tx.borrow_mut() = Some(this.update(&mut cx, |this, _| { *tx.borrow_mut() = Some(this.update(&mut cx, |this, cx| {
// Record the fact that the buffer is no longer loading. // Record the fact that the buffer is no longer loading.
this.loading_buffers.remove(&path); this.loading_buffers.remove(&path);
let buffer = load_result.map_err(Arc::new)?; let buffer = load_result.map_err(Arc::new)?;
this.open_buffers this.open_buffers.insert(
.insert(buffer.id(), OpenBuffer::Loaded(buffer.downgrade())); buffer.read(cx).remote_id() as usize,
OpenBuffer::Loaded(buffer.downgrade()),
);
Ok((buffer, Arc::new(AtomicBool::new(true)))) Ok((buffer, Arc::new(AtomicBool::new(true))))
})); }));
}) })
@ -1109,7 +1111,7 @@ impl Project {
if is_shared { if is_shared {
worktree worktree
.update(&mut cx, |worktree, cx| { .update(&mut cx, |worktree, cx| {
worktree.as_local_mut().unwrap().share(cx) worktree.as_local_mut().unwrap().share(project_id, cx)
}) })
.await?; .await?;
} }

View file

@ -739,13 +739,11 @@ impl LocalWorktree {
}) })
} }
pub fn share(&mut self, cx: &mut ModelContext<Worktree>) -> Task<anyhow::Result<()>> { pub fn share(
let project_id = if let Registration::Done { project_id } = self.registration { &mut self,
project_id project_id: u64,
} else { cx: &mut ModelContext<Worktree>,
return Task::ready(Err(anyhow!("cannot share worktree before registering it"))); ) -> Task<anyhow::Result<()>> {
};
if self.share.is_some() { if self.share.is_some() {
return Task::ready(Ok(())); return Task::ready(Ok(()));
} }

View file

@ -1160,10 +1160,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id()); let worktree_id = worktree_a.read_with(&cx_a, |tree, _| tree.id());
@ -1298,10 +1296,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -1400,10 +1396,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -1470,7 +1464,9 @@ mod tests {
.condition(&mut cx_a, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a") .condition(&mut cx_a, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
.await; .await;
buffer_b buffer_b
.condition(&mut cx_b, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a") .condition(&mut cx_b, |buf, _| {
dbg!(buf.text()) == "i-am-c, i-am-b, i-am-a"
})
.await; .await;
buffer_c buffer_c
.condition(&mut cx_c, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a") .condition(&mut cx_c, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
@ -1550,10 +1546,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/dir", false, cx))
p.find_or_create_worktree_for_abs_path("/dir", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -1645,10 +1639,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/dir", false, cx))
p.find_or_create_worktree_for_abs_path("/dir", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -1725,10 +1717,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/dir", false, cx))
p.find_or_create_worktree_for_abs_path("/dir", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -1801,10 +1791,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -1890,10 +1878,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -2110,10 +2096,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a
@ -2617,10 +2601,8 @@ mod tests {
cx, cx,
) )
}); });
let (worktree_a, _) = project_a let worktree_a = project_a
.update(&mut cx_a, |p, cx| { .update(&mut cx_a, |p, cx| p.add_local_worktree("/a", false, cx))
p.find_or_create_worktree_for_abs_path("/a", false, cx)
})
.await .await
.unwrap(); .unwrap();
worktree_a worktree_a