mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 04:20:46 +00:00
Change the definition of check_invariants
- On the host, ensure that only one worktree can exist for a given absolute path. Asserting about buffers was cool but I think should be tackled in the context of leaning more on entry ids for collaboration (vs. buffer ids). - On the guest, ensure that all the opened buffers don't contain deferred operations.
This commit is contained in:
parent
53327e2bf0
commit
d171d8ccc4
2 changed files with 32 additions and 43 deletions
|
@ -397,17 +397,6 @@ impl Project {
|
||||||
.and_then(|buffer| buffer.upgrade(cx))
|
.and_then(|buffer| buffer.upgrade(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
|
||||||
pub fn has_deferred_operations(&self, cx: &AppContext) -> bool {
|
|
||||||
self.opened_buffers.values().any(|buffer| match buffer {
|
|
||||||
OpenBuffer::Strong(buffer) => buffer.read(cx).deferred_ops_len() > 0,
|
|
||||||
OpenBuffer::Weak(buffer) => buffer
|
|
||||||
.upgrade(cx)
|
|
||||||
.map_or(false, |buffer| buffer.read(cx).deferred_ops_len() > 0),
|
|
||||||
OpenBuffer::Loading(_) => false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn languages(&self) -> &Arc<LanguageRegistry> {
|
pub fn languages(&self) -> &Arc<LanguageRegistry> {
|
||||||
&self.languages
|
&self.languages
|
||||||
|
@ -416,43 +405,37 @@ impl Project {
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn check_invariants(&self, cx: &AppContext) {
|
pub fn check_invariants(&self, cx: &AppContext) {
|
||||||
if self.is_local() {
|
if self.is_local() {
|
||||||
let buffers = self.buffers(cx);
|
let mut worktree_root_paths = HashMap::default();
|
||||||
for (i, buffer) in buffers.iter().enumerate() {
|
for worktree in self.worktrees(cx) {
|
||||||
let buffer = buffer.read(cx);
|
let worktree = worktree.read(cx);
|
||||||
let path = buffer.file().unwrap().as_local().unwrap().abs_path(cx);
|
let abs_path = worktree.as_local().unwrap().abs_path().clone();
|
||||||
for other_buffer in &buffers[0..i] {
|
let prev_worktree_id = worktree_root_paths.insert(abs_path.clone(), worktree.id());
|
||||||
let other_buffer = other_buffer.read(cx);
|
assert_eq!(
|
||||||
let other_path = other_buffer
|
prev_worktree_id,
|
||||||
.file()
|
None,
|
||||||
.unwrap()
|
"abs path {:?} for worktree {:?} is not unique ({:?} was already registered with the same path)",
|
||||||
.as_local()
|
abs_path,
|
||||||
.unwrap()
|
worktree.id(),
|
||||||
.abs_path(cx);
|
prev_worktree_id
|
||||||
if other_path == path {
|
)
|
||||||
panic!(
|
}
|
||||||
"buffers {} and {} have the same absolute path: {:?}",
|
} else {
|
||||||
buffer.remote_id(),
|
let replica_id = self.replica_id();
|
||||||
other_buffer.remote_id(),
|
for buffer in self.opened_buffers.values() {
|
||||||
path,
|
if let Some(buffer) = buffer.upgrade(cx) {
|
||||||
);
|
let buffer = buffer.read(cx);
|
||||||
}
|
assert_eq!(
|
||||||
|
buffer.deferred_ops_len(),
|
||||||
|
0,
|
||||||
|
"replica {}, buffer {} has deferred operations",
|
||||||
|
replica_id,
|
||||||
|
buffer.remote_id()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
|
||||||
pub fn buffers(&self, cx: &AppContext) -> Vec<ModelHandle<Buffer>> {
|
|
||||||
self.opened_buffers
|
|
||||||
.values()
|
|
||||||
.filter_map(|buffer| match buffer {
|
|
||||||
OpenBuffer::Strong(buffer) => Some(buffer.clone()),
|
|
||||||
OpenBuffer::Weak(buffer) => buffer.upgrade(cx),
|
|
||||||
OpenBuffer::Loading(_) => None,
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn has_open_buffer(&self, path: impl Into<ProjectPath>, cx: &AppContext) -> bool {
|
pub fn has_open_buffer(&self, path: impl Into<ProjectPath>, cx: &AppContext) -> bool {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
|
|
|
@ -4293,6 +4293,12 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guest_client
|
||||||
|
.project
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.read_with(&guest_cx, |project, cx| project.check_invariants(cx));
|
||||||
|
|
||||||
for guest_buffer in &guest_client.buffers {
|
for guest_buffer in &guest_client.buffers {
|
||||||
let buffer_id = guest_buffer.read_with(&guest_cx, |buffer, _| buffer.remote_id());
|
let buffer_id = guest_buffer.read_with(&guest_cx, |buffer, _| buffer.remote_id());
|
||||||
let host_buffer = host_project.read_with(&host_cx, |project, cx| {
|
let host_buffer = host_project.read_with(&host_cx, |project, cx| {
|
||||||
|
|
Loading…
Reference in a new issue