Change integration tests to open buffers via the project

This commit is contained in:
Max Brunsfeld 2022-01-21 12:23:17 -08:00
parent a578d71ea2
commit 6751bd9d78
3 changed files with 88 additions and 100 deletions

View file

@ -476,9 +476,10 @@ impl Project {
pub fn open_buffer(
&mut self,
path: ProjectPath,
path: impl Into<ProjectPath>,
cx: &mut ModelContext<Self>,
) -> Task<Result<ModelHandle<Buffer>>> {
let path = path.into();
let worktree = if let Some(worktree) = self.worktree_for_id(path.worktree_id, cx) {
worktree
} else {
@ -520,6 +521,13 @@ impl Project {
})
}
#[cfg(any(test, feature = "test-support"))]
pub fn has_open_buffer(&self, path: impl Into<ProjectPath>, cx: &AppContext) -> bool {
let path = path.into();
self.worktree_for_id(path.worktree_id, cx)
.map_or(false, |tree| tree.read(cx).has_open_buffer(path.path, cx))
}
fn assign_language_to_buffer(
&mut self,
worktree: ModelHandle<Worktree>,
@ -1470,6 +1478,15 @@ impl Collaborator {
}
}
impl<P: AsRef<Path>> From<(WorktreeId, P)> for ProjectPath {
fn from((worktree_id, path): (WorktreeId, P)) -> Self {
Self {
worktree_id,
path: path.as_ref().into(),
}
}
}
#[cfg(test)]
mod tests {
use super::{Event, *};

View file

@ -322,14 +322,14 @@ impl Worktree {
.map(|(path, summary)| (path.0.clone(), summary.clone()))
}
pub fn loading_buffers<'a>(&'a mut self) -> &'a mut LoadingBuffers {
pub(crate) fn loading_buffers<'a>(&'a mut self) -> &'a mut LoadingBuffers {
match self {
Worktree::Local(worktree) => &mut worktree.loading_buffers,
Worktree::Remote(worktree) => &mut worktree.loading_buffers,
}
}
pub fn open_buffer(
pub(crate) fn open_buffer(
&mut self,
path: impl AsRef<Path>,
cx: &mut ModelContext<Self>,
@ -391,7 +391,7 @@ impl Worktree {
}
#[cfg(feature = "test-support")]
pub fn has_open_buffer(&self, path: impl AsRef<Path>, cx: &AppContext) -> bool {
pub(crate) fn has_open_buffer(&self, path: impl AsRef<Path>, cx: &AppContext) -> bool {
let mut open_buffers: Box<dyn Iterator<Item = _>> = match self {
Worktree::Local(worktree) => Box::new(worktree.open_buffers.values()),
Worktree::Remote(worktree) => {
@ -1577,16 +1577,6 @@ impl RemoteWorktree {
})
}
pub fn close_all_buffers(&mut self, cx: &mut MutableAppContext) {
for (_, buffer) in self.open_buffers.drain() {
if let RemoteBuffer::Loaded(buffer) = buffer {
if let Some(buffer) = buffer.upgrade(cx) {
buffer.update(cx, |buffer, cx| buffer.close(cx))
}
}
}
}
fn snapshot(&self) -> Snapshot {
self.snapshot.clone()
}